1

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, i.e. 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

4
  • I must have misundertood: why don't you define set with the configdata type, eg element name="set" type="configdata" ?
    – Damien
    Feb 9, 2011 at 11:57
  • I have simplified the code example compared to the real code. In my real code set is an extension of another complexType. set hold additional elements - and I would like it to also hold all sub-elements of configdata.
    – Witek
    Feb 9, 2011 at 12:09
  • So what you're really asking for here is to have the set element, extend multiple complex types?
    – pmartin
    Feb 9, 2011 at 14:42
  • Sorry for not being clear - maybe I over-simplified the code examples. I have tried rephrasing the question to make it more clear. I hope that helps. I am learing XSD by doing - so maybe that is the root cause of my problem. ;-)
    – Witek
    Feb 10, 2011 at 8:40

2 Answers 2

0

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.

2
  • It could help you if you don't want to have several definitions for configdata elements: you could define a named group with all configdata elements, use it to define configdata with the tree element>complexType>group, and then use it to extend the primitive type in the set element, with the tree element>complexType>complexContent>extension>group.
    – Damien
    Feb 10, 2011 at 9:11
  • That works ... and I have learned more about XSD! ;-) Many thanks for your help!
    – Witek
    Feb 10, 2011 at 9:31
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.