I\'ve been dealing with an API recently that requires nodes of the XML document to be in a particular order. I was wondering why they feel the need to enforce this when I ca
An enforced order makes it simpler for the consumer, which can look like:
consumeTransation:
consumeAddressIfPresent;
consumeAmountIfPresent;
consumeOrderIDIfPresent;
More significantly, the use of XML Schema for structure definition makes order more likely to be a requirement. That's because XML Schema has richer support for ordered lists (xs:sequence
) that for unordered lists (xs:all
). The latter have occurrence restrictions, are more difficult to validate, and are not extensible in the way sequences are. Some of that is improved in XML Schema 1.1, but most tools/APIs aren't there, yet.