XSD:我可以让一个元素继承一个祖先吗';什么规则?

XSD:我可以让一个元素继承一个祖先吗';什么规则?,xsd,Xsd,考虑以下几点: <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=

考虑以下几点:

<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="xGroup"/>
    </xs:choice>
</xs:complexType>


我想要发生的是,如果xGroup中的一个元素是a的子元素、孙子元素等,那么它的子元素必须是子组或xGroup的一部分。如果B是它的祖先,那么它的子级必须在子bgroup或xGroup中。

一个解决方案是为每个父类型创建不同的组和类型。按照上面的例子,它将变成:

<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>


但它似乎过于冗长。有更优雅的解决方案吗?

一种解决方案是为每个父类型创建不同的组和类型。按照上面的例子,它将变成:

<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>


但它似乎过于冗长。有更优雅的解决方案吗?

你能举个例子说明你想要实现什么以及为什么吗?与现实世界足够接近,让其他人能够理解的东西。你的问题对我来说太抽象了(尽管我承认,对于真正的XSD专家来说可能不太抽象)。@John-请看我发布的答案。这仍然没有意义吗?你能举一个例子说明你想要完成什么以及为什么吗?与现实世界足够接近,让其他人能够理解的东西。你的问题对我来说太抽象了(尽管我承认,对于真正的XSD专家来说可能不太抽象)。@John-请看我发布的答案。这仍然没有意义吗?