13
So habe ich einige XML wie folgt aus:Wie kann ich alle Elemente, die zu einem XPath in Python passen, mit lxml entfernen?
<bar>
<foo>Something</foo>
<baz>
<foo>Hello</foo>
<zap>Another</zap>
<baz>
<bar>
Und ich möchte alle foo Knoten entfernen. So etwas wie dies funktioniert nicht
params = xml.xpath('//foo')
for n in params:
xml.getroot().remove(n)
ValueError: Element is not a child of this node.
Giving Was ist eine nette Art und Weise, dies zu tun?
Dieses eine Behandlung funktioniert. Vielen Dank –