In XML, is order important?

后端 未结 11 2221
无人共我
无人共我 2020-11-28 11:25

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 examp

11条回答
  •  无人及你
    2020-11-28 12:06

    The order is potentially important, but it depends on what's being transmitted.

    In XHTML, for example, the order is extremely important - if you had sibling paragraphs in a random order, it would be very confusing!

    In many other cases, it's unimportant.

    XML is just a way of representing a tree of nodes. XML itself says that the order is important: APIs must preserve the order, for example - but it's up to whatever produces/interprets the data to really care about the order or not.

    The XML specification effectively has to "err on the side of ordering" - it's easy to ignore ordering if you don't care about it, but it's a pain to reconstruct ordering if APIs decide to switch things around. (You'd have to put the order into attributes etc.)

提交回复
热议问题