[英]In Python, is there an easy way to edit xml in place?
假设我要编辑xml中的节点并编辑其属性之一。 我希望能够做一个简单的文件比较,只看到一行已更改。 使用prettyprint转储xml会更改整个xml结构。
好吧,不要使用prettyprint。
例如,在xml.dom.minidom
中
doc = xml.dom.minidom.parse(inputfile)
do_something_with(doc)
outputfile.write(doc.toxml("utf-8").decode("utf-8"))
所有结构/空白等将保持不变。
考虑不要使用“简单文件差异”。 看到这个问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.