Saturday, 6 December 2014

Extending a choice in XML



I have read both 9008622 and 4216313. My question is related but slightly different. I have an XML schema with a number of different complexTypes that all look like this:



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


that is, most of the content is common, except for the items marked "NNN". Is there a way to use inheritance so that the common elements have to be set up only once? It is clear that I can do this for the attributes, but the <xs:choice> is tripping me up for the elements. Is my only option to put both



<xs:element name="indiv_NNN" type="Indiv_NNN" minOccurs="0"/>
<xs:element name="common-element" type="CommmonElement" minOccurs="0"/>


into the <xs:extension>? There must be a better way!


No comments:

Post a Comment