我已閱讀How to extend a choice complexType without sequencing the choice?和XML Schema: Extend xsd:choice so that union (not sequence) of choices is created。我的問題是相關的,但稍有不同。我有許多不同的complexTypes
的XML模式,所有看起來像這樣:在XSD中擴展選項
<xs:complexType name="Type_NNN">
<xs:choice>
<xs:element name="indiv_NNN" type="Indiv_NNN" minOccurs="0"/>
<xs:element name="common-element" type="CommmonElement" minOccurs="0"/>
</xs:choice>
<xs:attribute name="commonAtt-001" type="xs:string" use="required"/>
<xs:attribute name="commonAtt-002" type="xs:string" use="optional"/>
<xs:attribute name="commonAtt-003" type="xs:string" use="optional"/>
<xs:attribute name="commonAtt-004" type="xs:string" use="optional"/>
<xs:attribute name="commonAtt-005" type="xs:string" use="optional"/>
<xs:attribute name="commonAtt-006" type="xs:string" use="optional"/>
<xs:attribute name="commonAtt-007" type="xs:nonNegativeInteger"
use="optional" default="0"/>
<xs:attribute name="commonAtt-008" type="xs:string" use="optional"/>
<xs:attribute name="indivAtt-NNN" type="xs:string" use="optional"/>
</xs:complexType>
也就是說,大部分內容是共同的,除了項目標記爲「NNN」。有沒有辦法使用繼承,以便共同的元素只能被設置一次?很顯然,我可以爲屬性做到這一點,但<xs:choice>
正在讓我爲這些元素絆倒。我的唯一選擇是將
<xs:element name="indiv_NNN" type="Indiv_NNN" minOccurs="0"/>
<xs:element name="common-element" type="CommmonElement" minOccurs="0"/>
納入<xs:extension>
?一定會有更好的辦法!