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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t replace an element from the
ElementTreeyou can only work withElement.Even when you call
ElementTree.find()it’s just a shortcut forgetroot().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.