一种解决方案是为每个父类型创建不同的组和类型。按照上面的例子,它将变成:
<xs:complexType name="A">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="subAGroup"/>
<xs:group ref="xGroup"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="B">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="subBGroup"/>
<xs:group ref="yGroup"/>
</xs:choice>
</xs:complexType>
<xs:group name="xGroup">
<xs:choice>
<xs:element name="Element1" type="AEleType"/>
</xs:choice>
</xs:group>
<xs:complexType name="AEleType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="subAGroup"/>
<xs:group ref="xGroup"/>
</xs:choice>
</xs:complexType>
<xs:group name="yGroup">
<xs:choice>
<xs:element name="Element1" type="BEleType"/>
</xs:choice>
</xs:group>
<xs:complexType name="BEleType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="subBGroup"/>
<xs:group ref="yGroup"/>
</xs:choice>
</xs:complexType>
不过,这似乎过于冗长。有更优雅的解决方案吗?