【发布时间】:2018-11-21 20:32:35
【问题描述】:
我有一个 xml 类型的文档:
<configuration>
<appSettings>
<add key="title" value="Donny" />
<add key="updaterApplication" value="Updater v4.3" />
</appSettings>
</configuration>
我需要修改一个特定的条目,例如value="Updater v4.3" 到value="Updater v4.4",当添加key="updaterApplication"。
我试过了:
import xml.etree.ElementTree as ET
tree = ET.parse(my_file_name)
root = tree.getroot()
tkr_itms = root.findall('appSettings')
for elm in tkr_itms[0]:
print(elm)
print(elm.attributes)
print(elm.value)
print(elm.text)
但无法处理'< ... />'之间的内容。
【问题讨论】:
标签: python xml tags elementtree