我遇到了minidom的问题。我的代码是:
from lxml import etree as ET
from xml.dom import minidom
xml_string = ET.tostring(self.model)
reparsed = minidom.parseString(xml_string)
text = reparsed.toprettyxml(indent=" ")
我期待(当我尝试打印 xml_string 时,有正确的参数顺序)
<def id="A" set="normal"/>
但是minidom确实改为:
<def set="normal" id="A"/>
这是lxml树代码
temp = ET.SubElement(self.model,"def")
temp.set("id", A)
temp.set("set", "normal")