Why is node order important in XML?

后端 未结 5 613
庸人自扰
庸人自扰 2021-01-05 09:48

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

5条回答
  •  粉色の甜心
    2021-01-05 10:00

    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.

提交回复
热议问题