我有这个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
的元素之后。
答案 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?