Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In XML, is order important?

Tags:

xml

Is the order that elements of a common parent appear in XML a meaningful piece of data captured by the XML document, or is order not specified as being meaningful? For example, consider the two XML documents:

<people>  <person name="sam"/>  <person name="juni"/> </people> 

and

<people>  <person name="juni"/>  <person name="sam"/> </people> 

Are these documents considered to represent identical data, or is the difference in order captured?

like image 369
Landon Kuhn Avatar asked Jul 15 '09 13:07

Landon Kuhn


People also ask

Are XML attributes ordered?

XML attributes are re-ordered alphabetically by the DOM parser. Attributes are being displayed in alphabetical order suggesting that the parser is sorting them.

Is XML order dependent?

Unlike with attributes, where order is insignificant according to the XML Recommendation: Note that the order of attribute specifications in a start-tag or empty-element tag is not significant. Element order is significant in XML.

What comes first in XML document?

The first line of an XML document should be a declaration that this is an XML document, including the version of XML being used.


1 Answers

Order of elements is significant in XML, so in your example the two documents are different. Attribute order is not significant, though.

<people>   <person name="kathy" id="1"/> </people> 

This is exactly the same as:

<people>   <person id="1" name="kathy"/> </people> 
like image 197
Adam Ruth Avatar answered Sep 28 '22 19:09

Adam Ruth