1
假設我想在xml中編輯一個節點並編輯它的一個屬性。我想能夠做一個簡單的文件差異,只看到一行改變。使用prettyprint轉儲xml會更改整個xml結構。在Python中,有沒有簡單的方法來編輯xml?
假設我想在xml中編輯一個節點並編輯它的一個屬性。我想能夠做一個簡單的文件差異,只看到一行改變。使用prettyprint轉儲xml會更改整個xml結構。在Python中,有沒有簡單的方法來編輯xml?
那麼不要使用相紙。
在xml.dom.minidom
例如,如果你做
doc = xml.dom.minidom.parse(inputfile)
do_something_with(doc)
outputfile.write(doc.toxml("utf-8").decode("utf-8"))
所有的結構/空格等將保持不變。
考慮不使用「簡單文件差異」。 See this SO question。