【发布时间】:2017-01-13 04:55:22
【问题描述】:
这里是 Python 菜鸟。想知道删除所有带有updated 属性值为true 的“profile”标签的最干净和最好的方法是什么。
我尝试了以下代码,但它正在抛出:SyntaxError("cannot use absolute path on element")
root.remove(root.findall("//Profile[@updated='true']"))
XML:
<parent>
<child type="First">
<profile updated="true">
<other> </other>
</profile>
</child>
<child type="Second">
<profile updated="true">
<other> </other>
</profile>
</child>
<child type="Third">
<profile>
<other> </other>
</profile>
</child>
</parent>
【问题讨论】:
标签: python xml python-2.7 scripting elementtree