如何删除作为 XML 树中根元素的兄弟的处理指令?
我找不到任何功能可以做到这一点,并且经典方式不起作用,因为头/尾处理指令没有父级:
from lxml import etree
root = etree.XML("<ROOT/><?foo?>")
tail = root.getnext()
parent = tail.getparent() # parent is None
parent.remove(tail)
我得到:
Traceback (most recent call last):
File "/path/to/demo_remove_tail_pi.py", line 6, in <module>
parent.remove(tail)
AttributeError: 'NoneType' object has no attribute 'remove'