在碱基序列之前添加序列

时间:2014-10-07 17:15:34

标签: xml xsd

我有这个XML:

<Base>
  <ElementInBase />
  <OtherElementInBase />
</Base>

<Derived>
  <ElementInChildren />
  <ElementInBase />
  <OtherElementInBase />
</Derived>

所以基本上我想允许Derived中的另一个序列出现在来自父Base的序列之前。

目前我有这个架构:

<xs:complexType name="Base">
    <xs:sequence >
        <xs:element ref="ElementInBase"  minOccurs="0" maxOccurs="1" />
        <xs:element ref="OtherElementInBase "  minOccurs="0" maxOccurs="1" />
    </xs:sequence>
</xs:complexType>

<xs:complexType name="Derived">
    <xs:complexContent>
        <xs:extension base="Base">
            <xs:sequence>
                <xs:element name="ElementInChildren"  minOccurs="0" maxOccurs="1"></xs:element>
            </xs:sequence>
        </xs:extension>

    </xs:complexContent>
</xs:complexType>

但这只允许ElementInChildren位于Base的元素之后。

1 个答案:

答案 0 :(得分:1)

您只需将Base定义为元素组,并在Derived complexType中引用它:

<xs:group name="Base">
   <xs:sequence>
      <xs:element ref="ElementInBase"  minOccurs="0" maxOccurs="1"/>
      <xs:element ref="OtherElementInBase "  minOccurs="0" maxOccurs="1"/>
  </xs:sequence>
</xs:group>

<xs:complexType name="Derived">
  <xs:sequence>
    <xs:element name="ElementInChildren" minOccurs="0" maxOccurs="1"></xs:element>
    <xs:group ref="Base"/>
  </xs:sequence>
</xs:complexType>

这会将ElementInChildren放在Base

中定义的内容之前

另请阅读我的回答:In XML Schema, why does an element group tag even exist?