In Python ElementTree how can I get list of all ancestors of an element in tree ?

Posted by Rohit on Stack Overflow See other posts from Stack Overflow or by Rohit
Published on 2010-06-14T22:00:58Z Indexed on 2010/06/14 22:02 UTC
Read the original article Hit count: 196

Filed under:
|
|
|

I need "get_ancestors_recursively" function.
A sample run can be

>>> dump(tr)
<anc1>
  <anc2>
    <element> </element>
  </anc2>
</anc1>
>>> input_element = tr.getiterator("element")[0]
>>> get_ancestors_recursively(input_element)
['anc1', 'anc2']

Can somebody help me with this ?

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml