Preserving XML attribute order?

本秂侑毒 提交于 2019-12-02 07:21:03

问题


I know this question has been asked in the past, but they have all been dated a few years back. I am wondering if there has been any changes made to Python modules such as lxml, minidom, or etree that will allow us to preserve the attribute order in XML files without patching.

I need the order to be preserved as the program I am supplying the files to relies on it.

If there are no updates, what's the easiest way to implement this?


回答1:


The insignificance of attribute ordering is not a technical limitation to be lifted in future implementations of XML libraries.

Attribute order is insignificant per the XML Recommendation:

Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.

Thus, you should not base your design upon any particular ordering of attributes in XML.

In the very rare circumstances where an application absolutely must order XML attributes, see the section on attribute processing in the XML Normalization Recommendation or the Canonical XML Recommendation.



来源:https://stackoverflow.com/questions/51234136/preserving-xml-attribute-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!