Python lxml与minidom更改元素属性顺序

时间:2016-04-19 10:43:16

标签: python attributes lxml minidom

我遇到了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")

0 个答案:

没有答案