Search code examples
xmllanguage-specifications

Does the XML Specification say anything about order of elements?


I've heard a couple times that the XML specification indicates that XML is not ordered (e.g. if you expect order, then it's not really true XML). As far as I could find, the XML specification says nothing about the order of elements; neither that it was explicitly unordered, or suggesting that there be no order.

I already know that

But what I want to know, is: does the XML Specification (any version) say anything about order of elements?


Solution

  • Yes, the XML specification cares about element order. XML document type declarations (DTDs) are a part of the XML specification. They can be used to enforce a specific order of elements. The specification explicitly talks about element orders, e.g. here:

    ... governing the allowed types of the child elements and the order in which they are allowed to appear.

    An XML document which adheres to its DTD is considered valid.

    However, if you are just talking about well-formedness, but not about validity, then the order of the elements is not important.