Documentation on how to use the simpleElementTree Module.
This module provides optional integration with ElementTree, allowing XML documents to be parsed and placed directly into the Context. The contents of the XML document can then be accessed using an sub-set of XPATH from within TAL templates.
This function takes one parameter, which should be either a file-like object or a string holding the name of a file on the filesystem. The file is read, the XML it contains is parsed, and an instance of simpleTALES.ContextVariable is returned.
The returned ContextVariable can then be added to the Context using addGlobal in the normal way, e.g.
xmlTree = simpleElementTree.parseFile (file="input.xml")
context = simpleTALES.Context(allowPythonPath=1)
context.addGlobal ("input", xmlTree)
The Context variable provided by parseFile provides the following syntax for path access in TAL:
Here are some examples:
<html>
<body>
<h1 tal:attributes="class input/title/@type" tal:content="input/title">Title here</h1>
<ul>
<li tal:repeat="note input/findall/.//note">
<b tal:condition="note/@type" tal:replace="string: Note (${note/@type}) - $note and then some"></b>
</li>
</ul>
</body>
</html>
The full list of my published Software
Made with PubTal 3.5
Copyright 2021 Colin StewartEmail: colin at owlfish.com