Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get following sibling of an etree._Element

I am iterating over elements which I find in a xml file like so:

for elem in fileasxml.xpath("//elementname[some condition]"):
    do something

Now instead of do something I'd like to write the element I have found plus the first following-sibling to a file. Now I know how to write to a file, what I don't know is how to get the following sibling.

I've seen the getnext() method but it doesn't work since the element I'd like to get is not in elem.

Same reason I can't use elem.xpath()

Any ideas ?

like image 395
pypat Avatar asked Oct 21 '22 04:10

pypat


1 Answers

Okay I was wrong. I made a mistake adding the element I found to a new structure before finding the following sibling.

getnext() actually works !

like image 180
pypat Avatar answered Oct 24 '22 05:10

pypat