Alex Rivera | Logout

In XML, is order important?

Asked 2009-07-15T13:46:07.177
74

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?

xml
Edit
Report

1 Answer

1

I think those should be considered identical, but it's really up to the software or person reading it to decide. XML is just a way of writing out data. The application determines how that data is used and therefore much of the meaning.

If your application reads in all of the person elements and then alphabetizes them by name, then the order in the XML document is meaningless. If your application reads them in and assigns seats in the same order the people appear in the XML, then the order is very important.

It's up to the application that uses the data. If the order is important, it should be described in the specs for people generating the files.

answered 2009-07-15T13:52:09.137

Your Answer