两个兄弟姐妹的执行顺序是否依赖?

Is the order of two siblings implementation dependent?

如果我有这样一个 XML 文档:

<people>
    <person>
        <name> Mario </name>
        <age> 25 </age>
    </person>
    <person>
        <name> Lucas </name>
        <age> 32 </age>
    </person>
</people>

是否始终保证在文档顺序中,马里奥出现在卢卡斯之前?所以 Lucas 始终是 Mario 的下一个兄弟姐妹,还是依赖于实现?

与属性不同,where order is insignificant according to the XML Recommendation:

Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.

元素顺序在XML.[=18=中重要 ]

然而,令人惊讶的是,XML 建议并没有就一般元素顺序的重要性做出明确、明确的声明。语法暗示元素顺序很重要,但与属性不同的是,没有关于元素顺序重要性的明确声明。

following statement in the case of Element Type Declarations:

Definition: In this case, the constraint includes a content model, a simple grammar governing the allowed types of the child elements and the order in which they are allowed to appear.

但这是对 DTD 元素类型声明的引用。 XSD 可以类似地声明排序是重要的(通过 xsd:sequence)或无关紧要的(通过 xsd:all 文档有效性 。对于任何给定的应用程序,顺序可能仍然重要,也可能无关紧要——这取决于应用程序。 [感谢@C。 M. Sperberg-McQueen 对有效性相关性与任何给定应用程序目的相关性差异的有益澄清。]

元素排序的重要性在 XML Information Set Recommendation in Section 2.2 Element Information Items:

中阐述

An element information item has the following properties:

[...]

  1. [children] An ordered list of child information items, in document order. This list contains element, processing instruction, unexpanded entity reference, character, and comment information items, one for each element, processing instruction, reference to an unprocessed external entity, data character, and comment appearing immediately within the current element. If the element is empty, this list has no members.

虽然,正如@kjhughes 所说,XML 建议并没有明确说明,但所有基于 XML 构建的 API 和工具都假定元素顺序很重要,并被保留由解析器报告给应用程序。

毕竟,您不希望 Word 文档中的段落随机排列。 (这可能是因为 XML 设计人员专注于建模文档,所以他们什么也没说:这太明显了,不需要说。)