%D \module
%D   [       file=x-xtag,
%D        version=2009.09.23,
%D          title=\CONTEXT\ Modules,
%D       subtitle=\XML\ stream handler,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D Here we load the \MKII\ (mostly) streaming \XML\ parser. We
%D define a couple of catcode regimes first.

\endinput

\writestatus{xtag}{this module is obsolete, use the mkiv-xml features or use mkii instead}

%D Well, at this time (2011.12.28) I'm not sure if this code still works in
%D \MKIV. But in any case we move snippets here that are only needed for old
%D \MKII\ code.

\unprotect

\newif\ifforcefileexpansion % handy for document level overload

\def\installexpander#1#2#3% changed, no longer \convert..\to...
  {\setvalue{\s!do\c!expansion#1l}{#2}%
   \setvalue{\s!do\c!expansion#1g}{#3}}%

\def\doconvertexpanded#1#2#3% #4 % [l|g] \cs {kind} {data}
  {\csname   % that we assign all exp a value
     \s!do\c!expansion
     \ifforcefileexpansion
       \v!yes
     \else\ifcsname\s!do\c!expansion#3#1\endcsname
       #3%
     \else
       \s!default
     \fi\fi
     #1%
   \endcsname#2}% #3

\def\defconvertexpanded {\doconvertexpanded l}
\def\gdefconvertexpanded{\doconvertexpanded g}

\installexpander\v!command \defconvertedcommand  \gdefconvertedcommand
\installexpander\s!default \defconvertedargument \gdefconvertedargument
\installexpander\empty     \defconvertedargument \gdefconvertedargument
\installexpander\v!no      \defconvertedargument \gdefconvertedargument
\installexpander\v!yes     \defconvertedmeaning  \gdefconvertedmeaning
\installexpander\v!yes     \defconvertedmeaning  \gdefconvertedmeaning
\installexpander\v!strict  \defreducedargument   \gdefreducedargument
\installexpander {utf}     \defreducedtoutf      \gdefreducedtoutf

\def\dodefconvertedmeaning#1#2#3% watch the double expansion !
  {\bgroup
     \xdef\@@globalexpanded{#3}%
     \xdef\@@globalexpanded{\@@globalexpanded}%
   \egroup
   #1#2\@@globalexpanded}

\def\defconvertedmeaning {\dodefconvertedmeaning\defconvertedcommand}
\def\gdefconvertedmeaning{\dodefconvertedmeaning\gdefconvertedcommand}

\def\dodefreducedargument#1#2#3%
  {\begingroup
   \reducetocoding[raw]%
   \edef\ascii{#3}%
   \expandafter\endgroup\expandafter#1\expandafter#2\expandafter{\ascii}}

\def\defreducedargument {\dodefreducedargument\edef}
\def\gdefreducedargument{\dodefreducedargument\xdef}

\protect

%D The \XML\ modules.

\loadmarkfile{catc-xml}

\loadcorefile{xtag-ini.mkii}
\loadcorefile{xtag-ext.mkii}
\loadcorefile{xtag-exp.mkii}
\loadcorefile{xtag-pre.mkii} % has old encoding code
\loadcorefile{xtag-xsd.mkii} % will go away (stub anyway)
\loadcorefile{xtag-rng.mkii} % will go away (stub anyway)

\endinput
