【发布时间】:2010-07-29 02:49:01
【问题描述】:
所以我有一些这样的 XML:
<bar>
<foo>Something</foo>
<baz>
<foo>Hello</foo>
<zap>Another</zap>
<baz>
<bar>
我想删除所有的 foo 节点。这样的东西是行不通的
params = xml.xpath('//foo')
for n in params:
xml.getroot().remove(n)
给予
ValueError: Element is not a child of this node.
有什么好的方法可以做到这一点?
【问题讨论】: