I have defined the following two types in my XSD-file:
<complexType name="primitive">
<attribute name="seq_num" type="int"/>
<element name="prim_to" type="int"/>
</complexType>
<complexType name="configdata">
<sequence>
<element name="enable" type="boolean"/>
<element name="type" default="int"/>
</sequence>
</complexType>
Both types are used in a number of definitions, ie I would rather not change these them. I would like to define a new element set
which extends primitive
and contains all sub-elements of configdata
. The XML-file for this element would look like this (please note, that enable
and type
are at the same level as prim_to
):
<set seq_num="1234">
<prim_to>22</prim_to>
<enable>true<enable>
<type>42</type>
</set>
I could declare set
the following way:
<element name="set">
<complexType>
<complexContent>
<extension base="primitive">
<sequence>
<element name="config" type="configdata"/>
</sequence>
</extension>
</complexContent>
</complexType>
</element>
In this case the XML-file would look like this:
<set seq_num="1234">
<prim_to>22</prim_to>
<config>
<enable>true<enable>
<type>42</type>
</config>
</set>
My challenge is to define set
in such a way that it extends primitive
and contains all sub-elements of configdata
- but does not contain an element of the type configdata
. Basically for the XML-file above it is a question of not having the two 'config'-tags. Is this possible in XSD? I would highly appreciate any hints.
Thanks in Advance,
Witek
A type can only extend a single other one (in other words, there is no multiple inheritance). So, your set element can extend configdata (with xsd:extension) and have additional elements, or it can extend another type and you could copy configdata elements to extend it. You can use groups to avoid redundancy.
You should define the set
element like this:
<element name="set" type="configdata" />
Using this structure, the set
element will contain the two child elements in the configdata complex type.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.