2009-10-16 29 views
1

我有一個複雜的類型定義,它當前不包含任何minOccurs限制。當我使用這個comlpex類型作爲一個元素類型時,我有時候希望這些元素具有minOccurs 0,其他時間1。XSD Make minOccurs取決於包含的類型

<xsd:complexType name="Identifier"> 
    <xsd:sequence> 
     <xsd:element name="Id" type="xsd:string"/> 
     <xsd:element name="Version" type="xsd:string"/> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="Wibble"> 
    <xsd:sequence> 
     <xsd:element name="Id" type="Identifier"/> <!-- I want all elements of Identifier to be mandatory when used as part of a 'Wibble' --> 
    </xsd:sequence> 
</xsd:complexType> 


<xsd:complexType name="Wobble"> 
    <xsd:sequence> 
     <xsd:element name="Id" type="Identifier"/> <!-- I want all elements of Identifier to be optional when used as part of a 'Wobble' --> 
    </xsd:sequence> 
</xsd:complexType> 

這可能嗎?

在此先感謝。

回答

1

羣組是你的朋友,例如,

<xsd:group name="IdentifierGroup"> 
    <xsd:sequence> 
     <xsd:element name="Id" type="Identifier"/> 
    </xsd:sequence> 
</xsd:group> 

<xsd:complexType name="Wibble"> 
    <xsd:sequence> 
     <xsd:group ref="IdentifierGroup" minOccurs="1"/> 
     <!-- more elements for Wibble here --> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="Wobble"> 
    <xsd:sequence> 
     <xsd:group ref="IdentifierGroup" minOccurs="0"/> 
     <!-- more elements for Wobble here --> 
    </xsd:sequence> 
</xsd:complexType> 
+1

今天我正在學習愛羣體!乾杯 – ng5000 2009-10-16 15:13:31