In XML, is order important?

后端 未结 11 2195
无人共我
无人共我 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:24

    The XML 1.0 Spec does not say anything about the order of elements with equal names as children of the same parent element. So it seems, the issue is undefined.

    However, most XML parsers and APIs will preserve the sequence as given in the textual representation. So, it is possible to implement applications that care about the element order. And the de facto answer to your question is: Yes, the order matters. The two examples are different.

    Looking more closely, you'll need to eveluate what your use case is. If your XML needs to interoperate with different (maybe 3rd party) applications, you should always assume that order matters. If you have total control on the producing and consuming application, then you might relax this rule.

    As always, you'll have to judge.

提交回复
热议问题