Package lxml :: Module etree :: Class ElementDepthFirstIterator
[frames] | no frames]

Class ElementDepthFirstIterator

        object --+    
                 |    
_ElementTagMatcher --+
                     |
                    ElementDepthFirstIterator

ElementDepthFirstIterator(self, node, tag=None, inclusive=True) Iterates over an element and its sub-elements in document order (depth first pre-order).

Note that this also includes comments, entities and processing instructions. To filter them out, check if the tag property of the returned element is a string (i.e. not None and not a factory function), or pass the Element factory for the tag keyword.

If the optional tag argument is not None, the iterator returns only the elements that match the respective name and namespace.

The optional boolean argument 'inclusive' defaults to True and can be set to False to exclude the start element itself.

Note that the behaviour of this iterator is completely undefined if the tree it traverses is modified during iteration.

Instance Methods
 
__init__(self, node, tag=None, inclusive=True)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__iter__(...)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__next__(...)
the next value, or raise StopIteration
next(x)

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

Properties

Inherited from object: __class__

Method Details

__init__(self, node, tag=None, inclusive=True)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__

__new__(T, S, ...)

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