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 ?
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With