Inheritance 每个元素类型可以有多个替换组吗?
假设您在架构中具有以下内容:Inheritance 每个元素类型可以有多个替换组吗?,inheritance,xsd,Inheritance,Xsd,假设您在架构中具有以下内容: <xsd:complexType name="shape"/> <xsd:complexType name="circle"> <xsd:complexContent> <xsd:extension base="shape"> <xsd:attribute name="radius" type="xs
<xsd:complexType name="shape"/>
<xsd:complexType name="circle">
<xsd:complexContent>
<xsd:extension base="shape">
<xsd:attribute name="radius" type="xsd:double"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="arc">
<xsd:complexContent>
<xsd:extension base="circle">
<xsd:attribute name="startAngle" type="xsd:double"/>
<xsd:attribute name="endAngle" type="xsd:double"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
这样就可以添加这样的替换组
<xsd:element name="shape" type="shape" abstract="true"/>
<xsd:element name="circle" type="circle" substitutionGroup="shape"/>
<xsd:element name="arc" type="arc" substitutionGroup="shape"/>
然后通过引用以下组来接受这些类型中的任何一种:
<xsd:element ref="shape"/>
那部分不是问题
但是,如果我也想允许(在另一部分中)只使用圆及其子类型,该怎么办
是否可以添加多个替换组以模拟模式中的正确继承?我尝试添加另一种元素类型,如:
<xsd:element name="shape" type="shape" abstract="true"/>
<xsd:element name="circle" type="circle" substitutionGroup="shape"/>
<xsd:element name="arc" type="arc" substitutionGroup="shape"/>
<xsd:element name="arc2" type="arc" substitutionGroup="circle"/>
但是我不希望根据我的预期更改预期元素的名称
有更好的方法吗?您应该能够保持
弧
作为圆
的替代。无论你在哪里使用shape
,要么circle
要么arc
然后应用,无论你在哪里使用circle
,要么circle
或者arc
疯狂-我可以发誓我以前试过。非常感谢。