<storage>
<record>
<values>
<points>99999999</points>
<points>Mr</points>
<points>Marvin</points>
<points>Homes</points>
<points>hardware</points>
<points>true</points>
<points>de</points>
<points>6</points>
<points>false</points>
</values>
</record>
</storage>
你好,如何用python(xml.etree.ElementTree)解決下一個問題?
我試圖改變一些XML值與Python(xml.etree.ElementTree)。 這是xml數據的一小部分。
appelation=re.compile("Mr")
for fname in root.iter('points'):
if appelation.match(str(pTest)):
fname.text="New Mr/Mrs"
## here i am trying to edit the next iter (<points>Marvin</points>)
##fname.next().text="New name" -> doesnt work
任何建議如何解決下一個iter? xml文件有很多名爲<「points」>的標籤,並且值始終不一樣。
你可以設置一個變量(match_found = TRUE),然後繼續下一個迭代 – Moberg
我不明白的問題。什麼是「pTest」的價值? – lucasnadalutti
您使用哪個ElementTree? xml.etree.ElementTree或lxml.etree? –