我已阅读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>
?一定会有更好的办法!