Next / Previous / Contents / TCC Help System / NM Tech homepage

9.17. Element.itersiblings(): Find other children of the same parent

For any Element instance E, this method returns an iterator that visits all of E's siblings, that is, the element children of its parent, in document order, but omitting E.

E.itersiblings(preceding=False)

If the preceding argument is false, the iterator will visit the siblings following E in document order. If you pass preceding=True, the iterator will visit the siblings that precede E in document order.

Example:

>>> root=etree.fromstring(
...   "<mom><aaron/><betty/><clarence/><dana/></mom>")
>>> betty=root.find('betty')
>>> for sib in betty.itersiblings(preceding=True):
...     print sib.tag
... 
aaron
>>> for sib in betty.itersiblings():
...     print sib.tag
... 
clarence
dana
>>>