in other words:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag1>
<tag1.1></tag1.1>
</tag1>
<tag2 />
<root>
is the same as:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag2 />
<tag1>
<tag1.1></tag1.1>
</tag1>
<root>
?
According to the XML specification, the order of attribute specifications in a start-tag or empty-element tag is not significant.
Well Formed XML DocumentsXML documents must have a root element. XML elements must have a closing tag. XML tags are case sensitive. XML elements must be properly nested.
XML attributes are re-ordered alphabetically by the DOM parser. Attributes are being displayed in alphabetical order suggesting that the parser is sorting them.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With