簡體   English   中英

在Python中,有沒有一種簡單的方法可以就地編輯xml?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM