I have a list of numbers that need to be ordered. Currently they are in the XML as such:
0.2
0.4
&l
Elements in XML are inherently ordered per their order in the document. This order is significant (unlike that of attributes) and will be preserved by parsers.
XML documents must have a single root element, so let's wrap your example elements in a single containing element:
0.2
0.4
0.6
1.8
An XSD can be written for this XML:
But an improvement is immediately obvious: Eliminate the indexing number from the component name:
0.2
0.4
0.6
1.8
The XSD for this improved XML is similarly streamlined (and also can actually handle an indefinite number of value
elements as well):
Now one might ask whether the XSD can enforce a sorted order on the elements such that
0.2
0.4
0.6
would be valid, but
0.6
0.2
0.4
would be invalid.
This is not possible to do in XSD 1.0, however XSD 1.1 can express such a constraint via assertions.
Credit: The idea for the assertion test is based on one from Michael Kay.