I am using org.w3c.dom.Element for adding elements to a xml file. Problem here is when setting attributes it adding 开发者_如何学Pythonaccording to the alphabetic order instead of adding order. How to ignore that behavior?
Thank you.
If you mean the order in a resulting serialized form of the XML document, the order of attributes is not significant. From the spec:
Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.
As @T.J. Crowder says, the order of attributes in a serialized XML document is not significant. (And the order of attributes is not part of the XML infoset.)
What this means is that implementations of the DOM, XML parsers and XML serializers are under no obligation to allow to let you specify a particular ordering for attributes in a DOM, or to preserve the apparent ordering when serializing, parsing or transforming an XML document.
If you have some application (or test case) that depends on the order of XML attributes, it is broken and should be fixed.
精彩评论