Comment 1 for bug 479613

Revision history for this message
Olli Pottonen (olli-pottonen) wrote :

Yes there is a way to remove them, although it's not as straightforward as it should. Unlike some other XML libraries, lxml allows an element to occur in one place. That is, you can not copy an element to another place; attempting that moves it to the new location, removing it from the old.

So, let root be the root element (lxml.etree._Element object) in the example given by manu3d.
Call

pi1 = root.getprevious()
pi2 = root.getnext()
root.append(pi1)
root.append(pi2)

Now the tree is
<aRoot>
    <?thisCanBeDeletedLikeAllChildren?>
<?noWayToDeleteThis?><?noWayToDeleteThisEither?></aRoot>

Now you call

root.remove(pi1)
root.remove(pi2)

and you're done!