Changes

Jump to navigation Jump to search
2,710 bytes added ,  15:39, 23 September 2005
Replicate list post mixing X(HT)ML tables with TeX
< [[XML]]

There is a simple XML vocabulary built into ConTeXt, called ContML, that enables an XHTML-like markup to be processed with little effort. This description was born from a request on the list to process XML tables, so it's best to start with that example.

The module, in the source tree as [http://source.contextgarden.net/tex/context/base/x-contml.tex x-contml.tex], is included as with any module:
<texcode>
\usemodule [contml]
</texcode>
All of the elements defined in the contml module are defined in their own XML namespace. Normally, that would mean calling elements such as <tt><context:itemize></tt>. By calling an auto-namespace, we lose some of this redundant verbosity, and also gain some elements that look very familiar to those familiar with HTML coding:
<texcode>
\autoXMLnamespace [context]
</texcode>
We set up some colors and start out with some normal ConTeXt code before starting with XML data:
<texcode>
\setupcolors [state=start] % not necessary, helps with example
\starttext
\section{Some \ConTeXt}

\startXMLdata
</texcode>
The following XML fragment is then processed using the contml module:
<xmlcode>
<table frame="off" background="color" color="white" style="bold">
<tr backgroundcolor="red"> <td>some</td> <td>XML</td> </tr>
<tr backgroundcolor="blue"> <td>xx</td> <td>xx</td> </tr>
</table>
</xmlcode>
After closing the XML block, you can continue with normal TeX markup:
<texcode>
\stopXMLdata
I can also have normal \TeX-like
\inframed[frame=off,background=color,backgroundcolor=yellow]
{markup}.
\stoptext
</texcode>

The result looks a bit like this:

<context>
\usemodule [contml] % load the simple default xml vocab
\autoXMLnamespace [context] % avoid prefixing elements w/ context:
\setupcolors [state=start] % not necessary, helps with example

\starttext
\section{Some \ConTeXt}

\startXMLdata
<table frame="off" background="color" color="white" style="bold">
<tr backgroundcolor="red"> <td>some</td> <td>XML</td> </tr>
<tr backgroundcolor="blue"> <td>xx</td> <td>xx</td> </tr>
</table>
\stopXMLdata

I can also have normal \TeX-like
\inframed[frame=off,background=color,backgroundcolor=yellow]
{markup}.

\stoptext
</context>

Note that the XML block containing the table can be moved into a separate file. In this case, you would replace the section reading:
<xmlcode>
\startXMLdata
<table frame="off" background="color" color="white">
<tr backgroundcolor="red"> <td>some</td> <td>XML</td> </tr>
<tr backgroundcolor="green"> <td>xx</td> <td>xx</td> </tr>
</table>
\stopXMLdata
</xmlcode>
With:
<texcode>
\processXMLfilegrouped{table.xml}
</texcode>
Where the <tt>table.xml</tt> file contains the XML fragment.

Navigation menu