I want to replace child elements from one tree to another , based on some criteria. I can do this using Comprehension ? But how do we replace element in ElementTree?
You can't replace an element from the ElementTree
you can only work with Element
.
Even when you call ElementTree.find()
it's just a shortcut for getroot().find()
.
So you really need to:
The extraction of the parent element can be easy if your target is a root sub-element (just call getroot()
) otherwise you'll have to find it.
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