假设您的架构中有以下内容:
<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"/>
但我不想根据我的期望更改预期元素的名称。
有更好的方法吗?
最佳答案
您应该能够仅保留 arc
作为 circle
的替代品。无论您在哪里使用 shape
,都可以应用 circle
或 arc
,而在使用 circle
的地方,可以应用 圆
或弧
。
关于inheritance - 每个元素类型是否可以有多个替换组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2436017/