Is the tag order relevant for valid XML? Is the tag order relevant for valid XML? xml xml

Is the tag order relevant for valid XML?


In as much detail as they are shown, your two examples are semantically the same.

It's a common misunderstanding of XML that in a well-formed XML document the order of sibling elements is significant. The XML 1.0 spec specifies that attributes are unordered, however it says nothing about elements. Therefore an XML processor is free to report element siblings in any order it likes.

That said, I don't think any commonly used XML processors report elements in a different order to the order they appear in a document.

You ask about a 'valid' document – this implies that a DTD or schema is in use, and therefore it may (or may not) be the case that the order is relevant. There are mechanisms for a DTD or schema to specify that element order is relevant within a document. However, your examples don't show use of a DTD or schema.


It is not important for XML itself. Both documents are of course well-formed XML documents. However, they may not be valid; when validating with an XML Schema, it is possible to specify an order, and not providing the elements in that order will make the document invalid according to the schema. This can be done with the xsd:sequence element as described here


It depends on the DTD (or schema) of your language definition.