Mixing XML and ConTeXt

From ConTeXt wiki
Jump to: navigation, search


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
\section{Some \ConTeXt}


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>

After closing the XML block, you can continue with normal TeX markup:

I can also have normal \TeX-like 

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:

<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>



Where the table.xml file contains the XML fragment.


Personal tools
External Help