XML Samples¶
Data File¶
<sample>
<key1>value1</key1>
<key2>
<item>list item 1</item>
<item>list item 2</item>
<item special='yes'>list item 3</item>
</key2>
<mappingseries>
<mapping>
<cola special='yes'>a</cola>
<colb>b</colb>
<colc>c</colc>
</mapping>
<mapping>
<cola>A</cola>
<colb special='yes'>B</colb>
<colc>C</colc>
</mapping>
</mappingseries>
</sample>
Template File¶
.. -*- mode: rst -*-
Static Heading
--------------
Individual Item
~~~~~~~~~~~~~~~
{{ data.find('key1').text }}
List of Items
~~~~~~~~~~~~~
{% for item in data.find('key2') %}
- {{item.text}}
{% endfor %}
XPath for Items
~~~~~~~~~~~~~~~
See `XPath support <https://docs.python.org/3/library/xml.etree.elementtree.html#xpath-support>`_
{% for item in data.findall(".//*[@special='yes']") %}
- {{item.text}}
{% endfor %}
Loading the Template¶
.. datatemplate:xml:: sample.xml
:template: xml-sample.tmpl
Rendered Output¶
Static Heading¶
Individual Item¶
value1
List of Items¶
list item 1
list item 2
list item 3
XPath for Items¶
See XPath support
list item 3
a
B