XSD 扩展可以重新排序元素吗?

Can XSD extension re-order elements?

我想在 XML 模式中扩展一个类型,这样说:

<complexType name="alienInfo">
  <complexContent>
    <extension base="personalInfo">
      <sequence>
        <element name="planet" type="xsd:string"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>

其中

<complexType name="personalInfo">
  <sequence>
    <element name="name" type="xsd:string" />
    <element name="age" type="xsd:int" />
  </sequence>
</complexType>

但是我想改变构成元素的顺序。比如说,在 nameage 之前有 planet。这可能吗?

Deriving Types by Extension不能用来改变基类型中元素的顺序:

When a complex type is derived by extension, its effective content model is the content model of the base type plus the content model specified in the type derivation. Furthermore, the two content models are treated as two children of a sequential group.

我发现大多数关于元素排序的顾虑——允许任何顺序或更改现有顺序——最终确实是不必要的。我建议,如果扩展可以帮助您实现目标,则不必担心更改基本类型中元素的顺序。