1 <?xml version="1.0" encoding="ascii"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6 <title>lxml.etree.TreeBuilder</title>
7 <link rel="stylesheet" href="epydoc.css" type="text/css" />
8 <script type="text/javascript" src="epydoc.js"></script>
11 <body bgcolor="white" text="black" link="blue" vlink="#204080"
13 <!-- ==================== NAVIGATION BAR ==================== -->
14 <table class="navbar" border="0" width="100%" cellpadding="0"
15 bgcolor="#a0c0ff" cellspacing="0">
18 <th> <a
19 href="lxml-module.html">Home</a> </th>
22 <th> <a
23 href="module-tree.html">Trees</a> </th>
26 <th> <a
27 href="identifier-index.html">Indices</a> </th>
30 <th> <a
31 href="help.html">Help</a> </th>
33 <!-- Project homepage -->
34 <th class="navbar" align="right" width="100%">
35 <table border="0" cellpadding="0" cellspacing="0">
36 <tr><th class="navbar" align="center"
37 ><a class="navbar" target="_top" href="/">lxml API</a></th>
41 <table width="100%" cellpadding="0" cellspacing="0">
44 <span class="breadcrumbs">
45 <a href="lxml-module.html">Package lxml</a> ::
46 <a href="lxml.etree-module.html">Module etree</a> ::
47 Class TreeBuilder
51 <table cellpadding="0" cellspacing="0">
52 <!-- hide/show private -->
53 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
54 onclick="toggle_private();">hide private</a>]</span></td></tr>
55 <tr><td align="right"><span class="options"
56 >[<a href="frames.html" target="_top">frames</a
57 >] | <a href="lxml.etree.TreeBuilder-class.html"
58 target="_top">no frames</a>]</span></td></tr>
63 <!-- ==================== CLASS DESCRIPTION ==================== -->
64 <h1 class="epydoc">Class TreeBuilder</h1><p class="nomargin-top"></p>
65 <pre class="base-tree">
68 <a href="lxml.etree._SaxParserTarget-class.html" onclick="show_private();">_SaxParserTarget</a> --+
70 <strong class="uidshort">TreeBuilder</strong>
74 <dl class="rst-docutils">
75 <dt>TreeBuilder(self, element_factory=None, parser=None,</dt>
76 <dd>comment_factory=None, pi_factory=None,
77 insert_comments=True, insert_pis=True)</dd>
79 <p>Parser target that builds a tree from parse event callbacks.</p>
80 <p>The factory arguments can be used to influence the creation of
81 elements, comments and processing instructions.</p>
82 <p>By default, comments and processing instructions are inserted into
83 the tree, but they can be ignored by passing the respective flags.</p>
84 <p>The final tree is returned by the <tt class="rst-docutils literal">close()</tt> method.</p>
86 <!-- ==================== INSTANCE METHODS ==================== -->
87 <a name="section-InstanceMethods"></a>
88 <table class="summary" border="1" cellpadding="3"
89 cellspacing="0" width="100%" bgcolor="white">
90 <tr bgcolor="#70b0f0" class="table-header">
91 <td colspan="2" class="table-header">
92 <table border="0" cellpadding="0" cellspacing="0" width="100%">
94 <td align="left"><span class="table-header">Instance Methods</span></td>
95 <td align="right" valign="top"
96 ><span class="options">[<a href="#section-InstanceMethods"
97 class="privatelink" onclick="toggle_private();"
98 >hide private</a>]</span></td>
104 <td width="15%" align="right" valign="top" class="summary">
105 <span class="summary-type"> </span>
106 </td><td class="summary">
107 <table width="100%" cellpadding="0" cellspacing="0" border="0">
109 <td><span class="summary-sig"><a href="lxml.etree.TreeBuilder-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
110 <span class="summary-sig-arg">element_factory</span>=<span class="summary-sig-default">None</span>,
111 <span class="summary-sig-arg">parser</span>=<span class="summary-sig-default">None</span>,
112 <span class="summary-sig-arg">comment_factory</span>=<span class="summary-sig-default">None</span>,
113 <span class="summary-sig-arg">pi_factory</span>=<span class="summary-sig-default">None</span>,
114 <span class="summary-sig-arg">insert_comments</span>=<span class="summary-sig-default">True</span>,
115 <span class="summary-sig-arg">insert_pis</span>=<span class="summary-sig-default">True</span>)</span><br />
116 x.__init__(...) initializes x; see help(type(x)) for signature</td>
117 <td align="right" valign="top">
127 <td width="15%" align="right" valign="top" class="summary">
128 <span class="summary-type">a new object with type S, a subtype of T</span>
129 </td><td class="summary">
130 <table width="100%" cellpadding="0" cellspacing="0" border="0">
132 <td><span class="summary-sig"><a href="lxml.etree.TreeBuilder-class.html#__new__" class="summary-sig-name">__new__</a>(<span class="summary-sig-arg">T</span>,
133 <span class="summary-sig-arg">S</span>,
134 <span class="summary-sig-arg">...</span>)</span></td>
135 <td align="right" valign="top">
145 <td width="15%" align="right" valign="top" class="summary">
146 <span class="summary-type"> </span>
147 </td><td class="summary">
148 <table width="100%" cellpadding="0" cellspacing="0" border="0">
150 <td><span class="summary-sig"><a name="close"></a><span class="summary-sig-name">close</span>(<span class="summary-sig-arg">self</span>)</span><br />
151 Flushes the builder buffers, and returns the toplevel document
153 <td align="right" valign="top">
163 <td width="15%" align="right" valign="top" class="summary">
164 <span class="summary-type"> </span>
165 </td><td class="summary">
166 <table width="100%" cellpadding="0" cellspacing="0" border="0">
168 <td><span class="summary-sig"><a name="comment"></a><span class="summary-sig-name">comment</span>(<span class="summary-sig-arg">self</span>,
169 <span class="summary-sig-arg">comment</span>)</span><br />
170 Creates a comment using the factory, appends it (unless disabled)
172 <td align="right" valign="top">
182 <td width="15%" align="right" valign="top" class="summary">
183 <span class="summary-type"> </span>
184 </td><td class="summary">
185 <table width="100%" cellpadding="0" cellspacing="0" border="0">
187 <td><span class="summary-sig"><a name="data"></a><span class="summary-sig-name">data</span>(<span class="summary-sig-arg">self</span>,
188 <span class="summary-sig-arg">data</span>)</span><br />
189 Adds text to the current element. The value should be either an
190 8-bit string containing ASCII text, or a Unicode string.</td>
191 <td align="right" valign="top">
201 <td width="15%" align="right" valign="top" class="summary">
202 <span class="summary-type"> </span>
203 </td><td class="summary">
204 <table width="100%" cellpadding="0" cellspacing="0" border="0">
206 <td><span class="summary-sig"><a name="end"></a><span class="summary-sig-name">end</span>(<span class="summary-sig-arg">self</span>,
207 <span class="summary-sig-arg">tag</span>)</span><br />
208 Closes the current element.</td>
209 <td align="right" valign="top">
219 <td width="15%" align="right" valign="top" class="summary">
220 <span class="summary-type"> </span>
221 </td><td class="summary">
222 <table width="100%" cellpadding="0" cellspacing="0" border="0">
224 <td><span class="summary-sig"><a name="pi"></a><span class="summary-sig-name">pi</span>(<span class="summary-sig-arg">self</span>,
225 <span class="summary-sig-arg">target</span>,
226 <span class="summary-sig-arg">data</span>=<span class="summary-sig-default">None</span>)</span><br />
227 Creates a processing instruction using the factory, appends it
228 (unless disabled) and returns it.</td>
229 <td align="right" valign="top">
239 <td width="15%" align="right" valign="top" class="summary">
240 <span class="summary-type"> </span>
241 </td><td class="summary">
242 <table width="100%" cellpadding="0" cellspacing="0" border="0">
244 <td><span class="summary-sig"><a name="start"></a><span class="summary-sig-name">start</span>(<span class="summary-sig-arg">self</span>,
245 <span class="summary-sig-arg">tag</span>,
246 <span class="summary-sig-arg">attrs</span>,
247 <span class="summary-sig-arg">nsmap</span>=<span class="summary-sig-default">None</span>)</span><br />
248 Opens a new element.</td>
249 <td align="right" valign="top">
259 <td colspan="2" class="summary">
260 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
261 <code>__delattr__</code>,
262 <code>__format__</code>,
263 <code>__getattribute__</code>,
264 <code>__hash__</code>,
265 <code>__reduce__</code>,
266 <code>__reduce_ex__</code>,
267 <code>__repr__</code>,
268 <code>__setattr__</code>,
269 <code>__sizeof__</code>,
270 <code>__str__</code>,
271 <code>__subclasshook__</code>
276 <!-- ==================== PROPERTIES ==================== -->
277 <a name="section-Properties"></a>
278 <table class="summary" border="1" cellpadding="3"
279 cellspacing="0" width="100%" bgcolor="white">
280 <tr bgcolor="#70b0f0" class="table-header">
281 <td colspan="2" class="table-header">
282 <table border="0" cellpadding="0" cellspacing="0" width="100%">
284 <td align="left"><span class="table-header">Properties</span></td>
285 <td align="right" valign="top"
286 ><span class="options">[<a href="#section-Properties"
287 class="privatelink" onclick="toggle_private();"
288 >hide private</a>]</span></td>
294 <td colspan="2" class="summary">
295 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
296 <code>__class__</code>
301 <!-- ==================== METHOD DETAILS ==================== -->
302 <a name="section-MethodDetails"></a>
303 <table class="details" border="1" cellpadding="3"
304 cellspacing="0" width="100%" bgcolor="white">
305 <tr bgcolor="#70b0f0" class="table-header">
306 <td colspan="2" class="table-header">
307 <table border="0" cellpadding="0" cellspacing="0" width="100%">
309 <td align="left"><span class="table-header">Method Details</span></td>
310 <td align="right" valign="top"
311 ><span class="options">[<a href="#section-MethodDetails"
312 class="privatelink" onclick="toggle_private();"
313 >hide private</a>]</span></td>
319 <a name="__init__"></a>
321 <table class="details" border="1" cellpadding="3"
322 cellspacing="0" width="100%" bgcolor="white">
324 <table width="100%" cellpadding="0" cellspacing="0" border="0">
325 <tr valign="top"><td>
326 <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
327 <span class="sig-arg">element_factory</span>=<span class="sig-default">None</span>,
328 <span class="sig-arg">parser</span>=<span class="sig-default">None</span>,
329 <span class="sig-arg">comment_factory</span>=<span class="sig-default">None</span>,
330 <span class="sig-arg">pi_factory</span>=<span class="sig-default">None</span>,
331 <span class="sig-arg">insert_comments</span>=<span class="sig-default">True</span>,
332 <span class="sig-arg">insert_pis</span>=<span class="sig-default">True</span>)</span>
333 <br /><em class="fname">(Constructor)</em>
335 </td><td align="right" valign="top"
340 x.__init__(...) initializes x; see help(type(x)) for signature
348 <a name="__new__"></a>
350 <table class="details" border="1" cellpadding="3"
351 cellspacing="0" width="100%" bgcolor="white">
353 <table width="100%" cellpadding="0" cellspacing="0" border="0">
354 <tr valign="top"><td>
355 <h3 class="epydoc"><span class="sig"><span class="sig-name">__new__</span>(<span class="sig-arg">T</span>,
356 <span class="sig-arg">S</span>,
357 <span class="sig-arg">...</span>)</span>
359 </td><td align="right" valign="top"
366 <dt>Returns: a new object with type S, a subtype of T</dt>
374 <!-- ==================== NAVIGATION BAR ==================== -->
375 <table class="navbar" border="0" width="100%" cellpadding="0"
376 bgcolor="#a0c0ff" cellspacing="0">
379 <th> <a
380 href="lxml-module.html">Home</a> </th>
383 <th> <a
384 href="module-tree.html">Trees</a> </th>
387 <th> <a
388 href="identifier-index.html">Indices</a> </th>
391 <th> <a
392 href="help.html">Help</a> </th>
394 <!-- Project homepage -->
395 <th class="navbar" align="right" width="100%">
396 <table border="0" cellpadding="0" cellspacing="0">
397 <tr><th class="navbar" align="center"
398 ><a class="navbar" target="_top" href="/">lxml API</a></th>
402 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
404 <td align="left" class="footer">
405 Generated by Epydoc 3.0.1
406 on Thu Jul 9 18:29:53 2020
408 <td align="right" class="footer">
409 <a target="mainFrame" href="http://epydoc.sourceforge.net"
410 >http://epydoc.sourceforge.net</a>
415 <script type="text/javascript">
417 // Private objects are initially displayed (because if
418 // javascript is turned off then we want them to be
419 // visible); but by default, we want to hide them. So hide
420 // them unless we have a cookie that says to show them.