2010-03-12 65 views
3

假設你有一個架構如下:是否有可能每個元素類型有多個替代組?

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

但我寧願沒有改變取決於什麼我期待的預期元素的名稱。

有沒有更好的方法來做到這一點?

回答

3

您應該可以保留arc作爲circle的替代品。無論您使用shape,無論是circlearc然後適用,並且您使用circlecirclearc

+0

瘋狂 - 我可以發誓我曾嘗試過。謝謝 – Marc 2010-03-15 14:49:12

相關問題