Mixing XML and ConTeXt
< 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 x-contml.tex, is included as with any module:
\usemodule [contml]
All of the elements defined in the contml module are defined in their own XML namespace. Normally, that would mean calling elements such as <context:itemize>. 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:
\autoXMLnamespace [context]
We set up some colors and start out with some normal ConTeXt code before starting with XML data:
\setupcolors [state=start] % not necessary, helps with example \starttext \section{Some \ConTeXt} \startXMLdata
The following XML fragment is then processed using the contml module:
<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>
After closing the XML block, you can continue with normal TeX markup:
\stopXMLdata I can also have normal \TeX-like \inframed[frame=off,background=color,backgroundcolor=yellow] {markup}. \stoptext
The result looks a bit like this:
Note that the XML block containing the table can be moved into a separate file. In this case, you would replace the section reading:
\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
With:
\processXMLfilegrouped{table.xml}
Where the table.xml file contains the XML fragment.