lxml.etree.iterparse
Package lxml :: Module etree :: Class iterparse
[hide private]
[frames] | no frames]

Class iterparse

object --+
         |
        iterparse

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)

Incremental parser.

Parses XML into a tree and generates tuples (event, element) in a SAX-like fashion. event is any of 'start', 'end', 'start-ns', 'end-ns'.

For 'start' and 'end', element is the Element that the parser just found opening or closing. For 'start-ns', it is a tuple (prefix, URI) of a new namespace declaration. For 'end-ns', it is simply None. Note that all start and end events are guaranteed to be properly nested.

The keyword argument events specifies a sequence of event type names that should be generated. By default, only 'end' events will be generated.

The additional tag argument restricts the 'start' and 'end' events to those elements that match the given tag. The tag argument can also be a sequence of tags to allow matching more than one tag. By default, events are generated for all elements. Note that the 'start-ns' and 'end-ns' events are not impacted by this restriction.

The other keyword arguments in the constructor are mainly based on the libxml2 parser configuration. A DTD will also be loaded if validation or attribute default values are requested.

Available boolean keyword arguments:
Other keyword arguments:
Instance Methods [hide private]
 
__init__(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)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__iter__(x)
iter(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__next__(...)
 
makeelement(self, _tag, attrib=None, nsmap=None, **_extra)
Creates a new element associated with this parser.
the next value, or raise StopIteration
next(x)
 
set_element_class_lookup(self, lookup= None)
Set a lookup scheme for element classes generated from this parser.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  error_log
The error log of the last (or current) parser run.
  resolvers
The custom resolver registry of the last (or current) parser run.
  root
  version
The version of the underlying XML parser.

Inherited from object: __class__

Method Details [hide private]

__init__(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)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

set_element_class_lookup(self, lookup= None)

 

Set a lookup scheme for element classes generated from this parser.

Reset it by passing None or nothing.