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.iterparse</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> ::
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.iterparse-class.html"
58 target="_top">no frames</a>]</span></td></tr>
63 <!-- ==================== CLASS DESCRIPTION ==================== -->
64 <h1 class="epydoc">Class iterparse</h1><p class="nomargin-top"></p>
65 <pre class="base-tree">
68 <strong class="uidshort">iterparse</strong>
72 <p>iterparse(self, source, events=("end",), tag=None, attribute_defaults=False, dtd_validation=False, load_dtd=False, no_network=True, remove_blank_text=False, remove_comments=False, remove_pis=False, encoding=None, html=False, recover=None, huge_tree=False, schema=None)</p>
73 <p>Incremental parser.</p>
74 <p>Parses XML into a tree and generates tuples (event, element) in a
75 SAX-like fashion. <tt class="rst-docutils literal">event</tt> is any of 'start', 'end', 'start-ns',
77 <p>For 'start' and 'end', <tt class="rst-docutils literal">element</tt> is the Element that the parser just
78 found opening or closing. For 'start-ns', it is a tuple (prefix, URI) of
79 a new namespace declaration. For 'end-ns', it is simply None. Note that
80 all start and end events are guaranteed to be properly nested.</p>
81 <p>The keyword argument <tt class="rst-docutils literal">events</tt> specifies a sequence of event type names
82 that should be generated. By default, only 'end' events will be
84 <p>The additional <tt class="rst-docutils literal">tag</tt> argument restricts the 'start' and 'end' events to
85 those elements that match the given tag. The <tt class="rst-docutils literal">tag</tt> argument can also be
86 a sequence of tags to allow matching more than one tag. By default,
87 events are generated for all elements. Note that the 'start-ns' and
88 'end-ns' events are not impacted by this restriction.</p>
89 <p>The other keyword arguments in the constructor are mainly based on the
90 libxml2 parser configuration. A DTD will also be loaded if validation or
91 attribute default values are requested.</p>
92 <dl class="rst-docutils">
93 <dt>Available boolean keyword arguments:</dt>
94 <dd><ul class="rst-first rst-last rst-simple">
95 <li>attribute_defaults: read default attributes from DTD</li>
96 <li>dtd_validation: validate (if DTD is available)</li>
97 <li>load_dtd: use DTD for parsing</li>
98 <li>no_network: prevent network access for related files</li>
99 <li>remove_blank_text: discard blank text nodes</li>
100 <li>remove_comments: discard comments</li>
101 <li>remove_pis: discard processing instructions</li>
102 <li>strip_cdata: replace CDATA sections by normal text content (default: True)</li>
103 <li>compact: safe memory for short text content (default: True)</li>
104 <li>resolve_entities: replace entities by their text value (default: True)</li>
105 <li><dl class="rst-first rst-docutils">
106 <dt>huge_tree: disable security restrictions and support very deep trees</dt>
107 <dd>and very long text content (only affects libxml2 2.7+)</dd>
110 <li>html: parse input as HTML (default: XML)</li>
111 <li><dl class="rst-first rst-docutils">
112 <dt>recover: try hard to parse through broken input (default: True for HTML,</dt>
113 <dd>False otherwise)</dd>
118 <dt>Other keyword arguments:</dt>
119 <dd><ul class="rst-first rst-last rst-simple">
120 <li>encoding: override the document encoding</li>
121 <li>schema: an XMLSchema to validate against</li>
126 <!-- ==================== INSTANCE METHODS ==================== -->
127 <a name="section-InstanceMethods"></a>
128 <table class="summary" border="1" cellpadding="3"
129 cellspacing="0" width="100%" bgcolor="white">
130 <tr bgcolor="#70b0f0" class="table-header">
131 <td colspan="2" class="table-header">
132 <table border="0" cellpadding="0" cellspacing="0" width="100%">
134 <td align="left"><span class="table-header">Instance Methods</span></td>
135 <td align="right" valign="top"
136 ><span class="options">[<a href="#section-InstanceMethods"
137 class="privatelink" onclick="toggle_private();"
138 >hide private</a>]</span></td>
144 <td width="15%" align="right" valign="top" class="summary">
145 <span class="summary-type"> </span>
146 </td><td class="summary">
147 <table width="100%" cellpadding="0" cellspacing="0" border="0">
149 <td><span class="summary-sig"><a href="lxml.etree.iterparse-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
150 <span class="summary-sig-arg">source</span>,
151 <span class="summary-sig-arg">events</span>=<span class="summary-sig-default">("end"</span>,
152 <span class="summary-sig-arg">)</span>,
153 <span class="summary-sig-arg">tag</span>=<span class="summary-sig-default">None</span>,
154 <span class="summary-sig-arg">attribute_defaults</span>=<span class="summary-sig-default">False</span>,
155 <span class="summary-sig-arg">dtd_validation</span>=<span class="summary-sig-default">False</span>,
156 <span class="summary-sig-arg">load_dtd</span>=<span class="summary-sig-default">False</span>,
157 <span class="summary-sig-arg">no_network</span>=<span class="summary-sig-default">True</span>,
158 <span class="summary-sig-arg">remove_blank_text</span>=<span class="summary-sig-default">False</span>,
159 <span class="summary-sig-arg">remove_comments</span>=<span class="summary-sig-default">False</span>,
160 <span class="summary-sig-arg">remove_pis</span>=<span class="summary-sig-default">False</span>,
161 <span class="summary-sig-arg">encoding</span>=<span class="summary-sig-default">None</span>,
162 <span class="summary-sig-arg">html</span>=<span class="summary-sig-default">False</span>,
163 <span class="summary-sig-arg">recover</span>=<span class="summary-sig-default">None</span>,
164 <span class="summary-sig-arg">huge_tree</span>=<span class="summary-sig-default">False</span>,
165 <span class="summary-sig-arg">schema</span>=<span class="summary-sig-default">None</span>)</span><br />
166 x.__init__(...) initializes x; see help(type(x)) for signature</td>
167 <td align="right" valign="top">
177 <td width="15%" align="right" valign="top" class="summary">
178 <span class="summary-type"> </span>
179 </td><td class="summary">
180 <table width="100%" cellpadding="0" cellspacing="0" border="0">
182 <td><span class="summary-sig"><a name="__iter__"></a><span class="summary-sig-name">__iter__</span>(<span class="summary-sig-arg">x</span>)</span><br />
184 <td align="right" valign="top">
194 <td width="15%" align="right" valign="top" class="summary">
195 <span class="summary-type">a new object with type S, a subtype of T</span>
196 </td><td class="summary">
197 <table width="100%" cellpadding="0" cellspacing="0" border="0">
199 <td><span class="summary-sig"><a href="lxml.etree.iterparse-class.html#__new__" class="summary-sig-name">__new__</a>(<span class="summary-sig-arg">T</span>,
200 <span class="summary-sig-arg">S</span>,
201 <span class="summary-sig-arg">...</span>)</span></td>
202 <td align="right" valign="top">
212 <td width="15%" align="right" valign="top" class="summary">
213 <span class="summary-type"> </span>
214 </td><td class="summary">
215 <table width="100%" cellpadding="0" cellspacing="0" border="0">
217 <td><span class="summary-sig"><a name="__next__"></a><span class="summary-sig-name">__next__</span>(<span class="summary-sig-arg">...</span>)</span></td>
218 <td align="right" valign="top">
228 <td width="15%" align="right" valign="top" class="summary">
229 <span class="summary-type"> </span>
230 </td><td class="summary">
231 <table width="100%" cellpadding="0" cellspacing="0" border="0">
233 <td><span class="summary-sig"><a name="makeelement"></a><span class="summary-sig-name">makeelement</span>(<span class="summary-sig-arg">self</span>,
234 <span class="summary-sig-arg">_tag</span>,
235 <span class="summary-sig-arg">attrib</span>=<span class="summary-sig-default">None</span>,
236 <span class="summary-sig-arg">nsmap</span>=<span class="summary-sig-default">None</span>,
237 <span class="summary-sig-arg">**_extra</span>)</span><br />
238 Creates a new element associated with this parser.</td>
239 <td align="right" valign="top">
249 <td width="15%" align="right" valign="top" class="summary">
250 <span class="summary-type">the next value, or raise StopIteration</span>
251 </td><td class="summary">
252 <table width="100%" cellpadding="0" cellspacing="0" border="0">
254 <td><span class="summary-sig"><a name="next"></a><span class="summary-sig-name">next</span>(<span class="summary-sig-arg">x</span>)</span></td>
255 <td align="right" valign="top">
265 <td width="15%" align="right" valign="top" class="summary">
266 <span class="summary-type"> </span>
267 </td><td class="summary">
268 <table width="100%" cellpadding="0" cellspacing="0" border="0">
270 <td><span class="summary-sig"><a href="lxml.etree.iterparse-class.html#set_element_class_lookup" class="summary-sig-name">set_element_class_lookup</a>(<span class="summary-sig-arg">self</span>,
271 <span class="summary-sig-arg">lookup</span>=<span class="summary-sig-default"> None</span>)</span><br />
272 Set a lookup scheme for element classes generated from this parser.</td>
273 <td align="right" valign="top">
283 <td colspan="2" class="summary">
284 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
285 <code>__delattr__</code>,
286 <code>__format__</code>,
287 <code>__getattribute__</code>,
288 <code>__hash__</code>,
289 <code>__reduce__</code>,
290 <code>__reduce_ex__</code>,
291 <code>__repr__</code>,
292 <code>__setattr__</code>,
293 <code>__sizeof__</code>,
294 <code>__str__</code>,
295 <code>__subclasshook__</code>
300 <!-- ==================== PROPERTIES ==================== -->
301 <a name="section-Properties"></a>
302 <table class="summary" border="1" cellpadding="3"
303 cellspacing="0" width="100%" bgcolor="white">
304 <tr bgcolor="#70b0f0" class="table-header">
305 <td colspan="2" class="table-header">
306 <table border="0" cellpadding="0" cellspacing="0" width="100%">
308 <td align="left"><span class="table-header">Properties</span></td>
309 <td align="right" valign="top"
310 ><span class="options">[<a href="#section-Properties"
311 class="privatelink" onclick="toggle_private();"
312 >hide private</a>]</span></td>
318 <td width="15%" align="right" valign="top" class="summary">
319 <span class="summary-type"> </span>
320 </td><td class="summary">
321 <a name="error_log"></a><span class="summary-name">error_log</span><br />
322 The error log of the last (or current) parser run.
326 <td width="15%" align="right" valign="top" class="summary">
327 <span class="summary-type"> </span>
328 </td><td class="summary">
329 <a name="resolvers"></a><span class="summary-name">resolvers</span><br />
330 The custom resolver registry of the last (or current) parser run.
334 <td width="15%" align="right" valign="top" class="summary">
335 <span class="summary-type"> </span>
336 </td><td class="summary">
337 <a name="root"></a><span class="summary-name">root</span>
341 <td width="15%" align="right" valign="top" class="summary">
342 <span class="summary-type"> </span>
343 </td><td class="summary">
344 <a name="version"></a><span class="summary-name">version</span><br />
345 The version of the underlying XML parser.
349 <td colspan="2" class="summary">
350 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
351 <code>__class__</code>
356 <!-- ==================== METHOD DETAILS ==================== -->
357 <a name="section-MethodDetails"></a>
358 <table class="details" border="1" cellpadding="3"
359 cellspacing="0" width="100%" bgcolor="white">
360 <tr bgcolor="#70b0f0" class="table-header">
361 <td colspan="2" class="table-header">
362 <table border="0" cellpadding="0" cellspacing="0" width="100%">
364 <td align="left"><span class="table-header">Method Details</span></td>
365 <td align="right" valign="top"
366 ><span class="options">[<a href="#section-MethodDetails"
367 class="privatelink" onclick="toggle_private();"
368 >hide private</a>]</span></td>
374 <a name="__init__"></a>
376 <table class="details" border="1" cellpadding="3"
377 cellspacing="0" width="100%" bgcolor="white">
379 <table width="100%" cellpadding="0" cellspacing="0" border="0">
380 <tr valign="top"><td>
381 <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
382 <span class="sig-arg">source</span>,
383 <span class="sig-arg">events</span>=<span class="sig-default">("end"</span>,
384 <span class="sig-arg">)</span>,
385 <span class="sig-arg">tag</span>=<span class="sig-default">None</span>,
386 <span class="sig-arg">attribute_defaults</span>=<span class="sig-default">False</span>,
387 <span class="sig-arg">dtd_validation</span>=<span class="sig-default">False</span>,
388 <span class="sig-arg">load_dtd</span>=<span class="sig-default">False</span>,
389 <span class="sig-arg">no_network</span>=<span class="sig-default">True</span>,
390 <span class="sig-arg">remove_blank_text</span>=<span class="sig-default">False</span>,
391 <span class="sig-arg">remove_comments</span>=<span class="sig-default">False</span>,
392 <span class="sig-arg">remove_pis</span>=<span class="sig-default">False</span>,
393 <span class="sig-arg">encoding</span>=<span class="sig-default">None</span>,
394 <span class="sig-arg">html</span>=<span class="sig-default">False</span>,
395 <span class="sig-arg">recover</span>=<span class="sig-default">None</span>,
396 <span class="sig-arg">huge_tree</span>=<span class="sig-default">False</span>,
397 <span class="sig-arg">schema</span>=<span class="sig-default">None</span>)</span>
398 <br /><em class="fname">(Constructor)</em>
400 </td><td align="right" valign="top"
405 x.__init__(...) initializes x; see help(type(x)) for signature
413 <a name="__new__"></a>
415 <table class="details" border="1" cellpadding="3"
416 cellspacing="0" width="100%" bgcolor="white">
418 <table width="100%" cellpadding="0" cellspacing="0" border="0">
419 <tr valign="top"><td>
420 <h3 class="epydoc"><span class="sig"><span class="sig-name">__new__</span>(<span class="sig-arg">T</span>,
421 <span class="sig-arg">S</span>,
422 <span class="sig-arg">...</span>)</span>
424 </td><td align="right" valign="top"
431 <dt>Returns: a new object with type S, a subtype of T</dt>
438 <a name="set_element_class_lookup"></a>
440 <table class="details" border="1" cellpadding="3"
441 cellspacing="0" width="100%" bgcolor="white">
443 <table width="100%" cellpadding="0" cellspacing="0" border="0">
444 <tr valign="top"><td>
445 <h3 class="epydoc"><span class="sig"><span class="sig-name">set_element_class_lookup</span>(<span class="sig-arg">self</span>,
446 <span class="sig-arg">lookup</span>=<span class="sig-default"> None</span>)</span>
448 </td><td align="right" valign="top"
453 <p>Set a lookup scheme for element classes generated from this parser.</p>
454 <p>Reset it by passing None or nothing.</p>
460 <!-- ==================== NAVIGATION BAR ==================== -->
461 <table class="navbar" border="0" width="100%" cellpadding="0"
462 bgcolor="#a0c0ff" cellspacing="0">
465 <th> <a
466 href="lxml-module.html">Home</a> </th>
469 <th> <a
470 href="module-tree.html">Trees</a> </th>
473 <th> <a
474 href="identifier-index.html">Indices</a> </th>
477 <th> <a
478 href="help.html">Help</a> </th>
480 <!-- Project homepage -->
481 <th class="navbar" align="right" width="100%">
482 <table border="0" cellpadding="0" cellspacing="0">
483 <tr><th class="navbar" align="center"
484 ><a class="navbar" target="_top" href="/">lxml API</a></th>
488 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
490 <td align="left" class="footer">
491 Generated by Epydoc 3.0.1
492 on Thu Jul 9 18:29:53 2020
494 <td align="right" class="footer">
495 <a target="mainFrame" href="http://epydoc.sourceforge.net"
496 >http://epydoc.sourceforge.net</a>
501 <script type="text/javascript">
503 // Private objects are initially displayed (because if
504 // javascript is turned off then we want them to be
505 // visible); but by default, we want to hide them. So hide
506 // them unless we have a cookie that says to show them.