13
所以我有一些这样的XML:如何使用lxml删除所有在python中匹配xpath的元素?
<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.
什么是整洁的方式做到这一点?
此作品一种享受。谢谢 – 2010-07-29 03:59:05