Test whether a (removed?) element is in an element tree

11 Nov
2020
11 Nov
'20
9:12 a.m.
Hello,
Suppose I have an element tree:
xml = lxml.etree.XML(b"<a>bla <b>bla</b> bla <c>bla</c> bla <d/> bla</a>”)
and I get all of its elements:
elems = xml.xpath(".//*”) [<Element b at 0x10d1dad70>, <Element c at 0x10d1dad20>, <Element d at 0x10d1dacd0>]
Next, I remove some element from that tree:
c = xml.find("c”) # = elems[1] c.getparent().remove(c)
How can I now test whether that element is still in the element tree?
c.getparent() # elems[1].getparent()
returns None, but is that a sure test? I can’t find documentation on how to identify elements that don’t belong to a given element tree.
Much thanks! Jens
-- Jens Tröger http://savage.light-speed.de/
1051
Age (days ago)
1051
Last active (days ago)
0 comments
1 participants
participants (1)
-
Jens Tröger