用python修改xml节点后如何保存回xml文件里?
- XML code
<?xml version="1.0" encoding="utf-8"?><config> <id>0</id> <log_path>E:/Python</log_path></config>
- Python code
from xml.etree import ElementTreexml_file='config.xml'xml=ElementTree.ElementTree(file=xml_file).getroot()xml.find('id').text=1
请问这样更改id节点的值为1之后,如何保存回xml文件里?
[解决办法]
xml.write("output.xml")