问题描述
我正在尝试使用python中的ElemetTree修改xml文件中的几个字段。但是我看到ns0:的前缀添加到了每个节点。
代码:
tree = ET.parse(xml_file)
root = tree.getroot()
for domU_id in domU_id_list:
logger.info("Updating dns for domU_id == " + domU_id)
index = 0
for item in root.findall('{model}machines/{model}machine[@id="' + domU_id + '"]/{model}dnsServers/{model}dnsServer/{model}ipAddress'):
logger.info(" Old dns == " + item.text + " New dns == " + dns_ips[index])
item.text = dns_ips[index]
index = index + 1
tree.write(xml_file)
之前:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<engineeredSystem xmlns="model" oversion="180321" filetype="AS">
<customerName>qaservices</customerName>
<departmentName>depone</departmentName>
<esPrefix>prefone</esPrefix>
<version>version1</version>
<machines>
...
之后
<ns0:engineeredSystem xmlns:ns0="model" filetype="AS" oversion="180321">
<ns0:customerName>qaservices</ns0:customerName>
<ns0:departmentName>depone</ns0:departmentName>
<ns0:esPrefix>prefone</ns0:esPrefix>
<ns0:version>version1</ns0:version>
<ns0:machines>
...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)