Re: [lxml] Test whether a (removed?) element is in an element tree

Hi,
IIRC: getparent() also returns None for a root element. As far as I remember each element always belongs to one unique tree, which gets created on-the-fly for an element that you remove from a tree. So I don't quite see the usecase, but you could check if c.getroottree() is the same tree object as your original/other tree (i.e. xml.getroottree()). Best regards Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart HRA 4356, HRA 104 440 Amtsgericht Mannheim HRA 40687 Amtsgericht Mainz Die LBBW verarbeitet gemaess Erfordernissen der DSGVO Ihre personenbezogenen Daten. Informationen finden Sie unter https://www.lbbw.de/datenschutz.

Holger.Joukl@LBBW.de schrieb am 11.11.20 um 15:17:
Let's say, any element without a parent. If an element is removed from the tree (and note that you cannot remove a root element "from its tree", because it has no parent to remove it from), then it will not have a parent afterwards any more. So this is a safe test.
I could imagine test cases to make use of this property, but apart from that … if an element is removed, it's removed.
you could check if c.getroottree() is the same tree object as your original/other tree (i.e. xml.getroottree()).
That seems unnecessarily complicated to me. Stefan

Holger.Joukl@LBBW.de schrieb am 11.11.20 um 15:17:
Let's say, any element without a parent. If an element is removed from the tree (and note that you cannot remove a root element "from its tree", because it has no parent to remove it from), then it will not have a parent afterwards any more. So this is a safe test.
I could imagine test cases to make use of this property, but apart from that … if an element is removed, it's removed.
you could check if c.getroottree() is the same tree object as your original/other tree (i.e. xml.getroottree()).
That seems unnecessarily complicated to me. Stefan
participants (2)
-
Holger.Joukl@LBBW.de
-
Stefan Behnel