replacing xml elements with other elements using lxml

Stefan Behnel stefan.behnel-n05pAM at
Thu Aug 30 09:17:59 CEST 2007

Ultrus wrote:
> Ah! I figured it out. I forgot that the tree is treated like a list.
> The solution was to replace the <random> element with the first <item>
> child, then use Python's insert(i,x) function to insert elements after
> the first one.

You could also use slicing, something like:

    parent[2:3] = child[1:5]

should work.

> lxml rocks!

I know, but it feels good to read it once in a while. :)


More information about the Python-list mailing list