擅长:python、mysql、java
<p>这将提取所需的元素,更新属性值并转储xml结果:</p>
<pre><code>import xml.etree.ElementTree as Etree
tree = Etree.parse("file.xml")
root = tree.getroot()
print(root)
z = root.findall(".//*[@password]")
for elm in z:
elm.attrib['password'] = "Password"
print(Etree.dump(root))
</code></pre>
<p>我只能在2.7.12上进行测试,因为它是我唯一的python2版本。如果可以的话,我绝对会推荐你升级,但是如果你不能升级的话,这会给你一个正确的方向</p>