Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i do replace a child element(s) in ElementTree

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?

like image 955
Ashish Avatar asked Jan 13 '12 03:01

Ashish


1 Answers

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:

  • extract the parent element
  • use comprehension (or whatever you like) on that parent element

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.

like image 150
Rik Poggi Avatar answered Nov 03 '22 12:11

Rik Poggi