File: api-simpleelementtree.html

package info (click to toggle)
python3-simpletal 5.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 812 kB
  • sloc: python: 5,797; xml: 23; makefile: 6
file content (51 lines) | stat: -rw-r--r-- 2,933 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>SimpleTAL API: simpleElementTree Module.</title>
	<link href="../style/site.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1>SimpleTAL API: simpleElementTree Module.</h1>
  <p id="subject">Documentation on how to use the simpleElementTree Module.</p>
  <div><h2>simpleElementTree</h2>
<p>This module provides integration with ElementTree, allowing XML documents to be parsed and placed directly into the Context.&nbsp; The contents of the XML document can then be accessed using an sub-set of XPATH from within TAL templates.</p>
<h3>parseFile (file)</h3>
<p>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.&nbsp; The file is read, the XML it contains is parsed, and an instance of simpleTALES.ContextVariable is returned.</p>
<p>The returned ContextVariable can then be added to the Context using addGlobal in the normal way, e.g.</p>
<pre>
<code>xmlTree = simpleElementTree.parseFile (file="input.xml")
context = simpleTALES.Context(allowPythonPath=1)
context.addGlobal ("input", xmlTree)</code>
</pre>
<h2>ElementTree Paths</h2>
<p>The Context variable provided by parseFile provides the following syntax for path access in TAL:</p>
<ul>
	<li>Accessing the variable directly returns the Text value for this node.</li>
	<li>Accessing variable/find/path returns the first node to match the path, as supported by ElementTree (see <a href="http://effbot.org/zone/element-xpath.htm">XPath Support in ElementTree</a>).</li>
	<li>Accessing variable/findall/path returns a list of nodes that match the path, as supported by ElementTree (see <a href="http://effbot.org/zone/element-xpath.htm">XPath Support in ElementTree</a>).</li>
	<li>Accessing variable@name returns the XML attribute "name".</li>
	<li>Accessing variable/anotherElement is a short-cut for variable/find/anotherElement.</li>
</ul>
<p>Here are some examples:</p>
<pre>
<code>&lt;html&gt;
&nbsp; &lt;body&gt;
&nbsp;&nbsp;&nbsp; &lt;h1 tal:attributes="class input/title/@type" tal:content="input/title"&gt;Title here&lt;/h1&gt;
&nbsp;&nbsp;&nbsp; &lt;ul&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li tal:repeat="note input/findall/.//note"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b tal:condition="note/@type" tal:replace="string: Note (${note/@type}) - $note and then some"&gt;&lt;/b&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;
&nbsp;&nbsp;&nbsp; &lt;/ul&gt;
&nbsp; &lt;/body&gt;
&lt;/html&gt;</code>
</pre>
</div>
	  
  <p id="version">PubTal Version </p>
  <div id="footer">
  <p>File: api-simpleelementtree.txt</p>
  <p>Last modified: Sat, 15 Aug 2009 12:30:36 BST</p>
  <p>Copyright 2011 Colin Stewart</p>
  <p title="PubTal is a template driven web site publisher.">Made with <a href="http://www.owlfish.com/software/PubTal/">PubTal</a> 3.5</p>
  </div>
</body>