source: exist/trunk/python/elementtree-1.3a6-20070220-badc/docs/pythondoc-elementtree.SimpleXMLWriter.html @ 3578

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/elementtree-1.3a6-20070220-badc/docs/pythondoc-elementtree.SimpleXMLWriter.html@3578
Revision 3578, 5.8 KB checked in by pjkersha, 11 years ago (diff)

Latest releases from Fredrik Lundh. 10 March release has exclusive C14N support with namespace prefixes.

Line 
1<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
2<html>
3<head>
4<meta http-equiv='Content-Type' content='text/html; charset=us-ascii' />
5<title>The elementtree.SimpleXMLWriter Module</title>
6<link rel='stylesheet' href='effbot.css' type='text/css' />
7</head>
8<body>
9<h1>The elementtree.SimpleXMLWriter Module</h1>
10<p>Tools to write XML files, without having to deal with encoding
11issues, well-formedness, etc.
12</p><p>
13The current version does not provide built-in support for
14namespaces. To create files using namespaces, you have to provide
15"xmlns" attributes and explicitly add prefixes to tags and
16attributes.
17
18<h3>Patterns</h3>
19
20The following example generates a small XHTML document.
21<pre>
22
23from elementtree.SimpleXMLWriter import XMLWriter
24import sys
25
26w = XMLWriter(sys.stdout)
27
28html = w.start("html")
29
30w.start("head")
31w.element("title", "my document")
32w.element("meta", name="generator", value="my application 1.0")
33w.end()
34
35w.start("body")
36w.element("h1", "this is a heading")
37w.element("p", "this is a paragraph")
38
39w.start("p")
40w.data("this is ")
41w.element("b", "bold")
42w.data(" and ")
43w.element("i", "italic")
44w.data(".")
45w.end("p")
46
47w.close(html)
48</pre>
49</p><h2>Module Contents</h2>
50<dl>
51<dt><b>XMLWriter(file, encoding=&quot;us-ascii&quot;)</b> (class) [<a href='#elementtree.SimpleXMLWriter.XMLWriter-class'>#</a>]</dt>
52<dd>
53<p>XML writer class.</p>
54<dl>
55<dt><i>file</i></dt>
56<dd>
57A file or file-like object.  This object must implement
58   a <b>write</b> method that takes an 8-bit string.
59</dd>
60<dt><i>encoding</i></dt>
61<dd>
62Optional encoding.</dd>
63</dl><br />
64<p>For more information about this class, see <a href='#elementtree.SimpleXMLWriter.XMLWriter-class'><i>The XMLWriter Class</i></a>.</p>
65</dd>
66</dl>
67<h2><a id='elementtree.SimpleXMLWriter.XMLWriter-class' name='elementtree.SimpleXMLWriter.XMLWriter-class'>The XMLWriter Class</a></h2>
68<dl>
69<dt><b>XMLWriter(file, encoding=&quot;us-ascii&quot;)</b> (class) [<a href='#elementtree.SimpleXMLWriter.XMLWriter-class'>#</a>]</dt>
70<dd>
71<p>XML writer class.</p>
72<dl>
73<dt><i>file</i></dt>
74<dd>
75A file or file-like object.  This object must implement
76   a <b>write</b> method that takes an 8-bit string.
77</dd>
78<dt><i>encoding</i></dt>
79<dd>
80Optional encoding.</dd>
81</dl><br />
82</dd>
83<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.close-method' name='elementtree.SimpleXMLWriter.XMLWriter.close-method'><b>close(id)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.close-method'>#</a>]</dt>
84<dd>
85<p>Closes open elements, up to (and including) the element identified
86by the given identifier.</p>
87<dl>
88<dt><i>id</i></dt>
89<dd>
90Element identifier, as returned by the <b>start</b> method.
91</dd>
92</dl><br />
93</dd>
94<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.comment-method' name='elementtree.SimpleXMLWriter.XMLWriter.comment-method'><b>comment(comment)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.comment-method'>#</a>]</dt>
95<dd>
96<p>Adds a comment to the output stream.</p>
97<dl>
98<dt><i>comment</i></dt>
99<dd>
100Comment text, as an 8-bit string or Unicode string.</dd>
101</dl><br />
102</dd>
103<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.data-method' name='elementtree.SimpleXMLWriter.XMLWriter.data-method'><b>data(text)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.data-method'>#</a>]</dt>
104<dd>
105<p>Adds character data to the output stream.</p>
106<dl>
107<dt><i>text</i></dt>
108<dd>
109Character data, as an 8-bit string or Unicode string.</dd>
110</dl><br />
111</dd>
112<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.declaration-method' name='elementtree.SimpleXMLWriter.XMLWriter.declaration-method'><b>declaration()</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.declaration-method'>#</a>]</dt>
113<dd>
114<p>Writes an XML declaration.</p>
115</dd>
116<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.element-method' name='elementtree.SimpleXMLWriter.XMLWriter.element-method'><b>element(tag, text=None, attrib={}, **extra)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.element-method'>#</a>]</dt>
117<dd>
118<p>Adds an entire element.  This is the same as calling <b>start</b>,
119<b>data</b>, and <b>end</b> in sequence. The <b>text</b> argument
120can be omitted.
121</p></dd>
122<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.end-method' name='elementtree.SimpleXMLWriter.XMLWriter.end-method'><b>end(tag=None)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.end-method'>#</a>]</dt>
123<dd>
124<p>Closes the current element (opened by the most recent call to
125<b>start</b>).
126
127</p><dl>
128<dt><i>tag</i></dt>
129<dd>
130Element tag.  If given, the tag must match the start
131   tag.  If omitted, the current element is closed.</dd>
132</dl><br />
133</dd>
134<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.flush-method' name='elementtree.SimpleXMLWriter.XMLWriter.flush-method'><b>flush()</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.flush-method'>#</a>]</dt>
135<dd>
136<p>Flushes the output stream.</p>
137</dd>
138<dt><a id='elementtree.SimpleXMLWriter.XMLWriter.start-method' name='elementtree.SimpleXMLWriter.XMLWriter.start-method'><b>start(tag, attrib={}, **extra)</b></a> [<a href='#elementtree.SimpleXMLWriter.XMLWriter.start-method'>#</a>]</dt>
139<dd>
140<p>Opens a new element.  Attributes can be given as keyword
141arguments, or as a string/string dictionary. You can pass in
1428-bit strings or Unicode strings; the former are assumed to use
143the encoding passed to the constructor.  The method returns an
144opaque identifier that can be passed to the <b>close</b> method,
145to close all open elements up to and including this one.
146
147</p><dl>
148<dt><i>tag</i></dt>
149<dd>
150Element tag.</dd>
151<dt><i>attrib</i></dt>
152<dd>
153Attribute dictionary.  Alternatively, attributes
154   can be given as keyword arguments.</dd>
155<dt>Returns:</dt>
156<dd>
157An element identifier.</dd>
158</dl><br />
159</dd>
160</dl>
161</body></html>
Note: See TracBrowser for help on using the repository browser.