在 XML 中,顺序重要吗?
问题描述:
公共父元素在 XML 中出现的顺序是 XML 文档捕获的有意义的数据片段,还是未指定的顺序有意义?例如,考虑两个 XML 文档:
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 example, consider the two XML documents:
<people>
<person name="sam"/>
<person name="juni"/>
</people>
和
<people>
<person name="juni"/>
<person name="sam"/>
</people>
这些文档是否被视为代表相同的数据,或者是否捕获了顺序差异?
Are these documents considered to represent identical data, or is the difference in order captured?
答
元素的顺序在 XML 中很重要,因此在您的示例中,这两个文档是不同的.不过,属性顺序并不重要.
Order of elements is significant in XML, so in your example the two documents are different. Attribute order is not significant, though.
<people>
<person name="kathy" id="1"/>
</people>
这与:
<people>
<person id="1" name="kathy"/>
</people>