【发布时间】:2014-12-07 02:14:44
【问题描述】:
我已经阅读了How to extend a choice complexType without sequencing the choice? 和XML Schema: Extend xsd:choice so that union (not sequence) of choices is created。我的问题是相关的,但略有不同。我有一个 XML Schema,其中包含许多不同的 complexTypes,它们看起来都像这样:
<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>?一定有更好的办法!
【问题讨论】: