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
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 DeletedLikeAllC hildren? > This?>< ?noWayToDeleteT hisEither? ></aRoot>
<aRoot>
<?thisCanBe
<?noWayToDelete
Now you call
root.remove(pi1)
root.remove(pi2)
and you're done!