views:

46

answers:

1

Hi,

I have written a XMLSchema which looks like the one below. The idea is that baseContainer only allows some tags and fullContainer allows all tags in baseContainer + some other tags. The tags may come in any order and there can be multiple of all the tags. In my real sample there is a lot more tags so this method of write XMLSchema tends to become big and unstructured. I want to use XMLSchema extension tag to structure the doc but it do not work as I expect.

Thanks in advance :)

<complexType name="baseContainer">
  <sequence minOccurs="0" maxOccurs="unbounded">
    <choice minOccurs="0" maxOccurs="1">
      <element ref="w:aTag0"/>
      <element ref="w:aTag1"/>
      <element ref="w:aTag2"/>
    </choice>
  </sequence>
</complexType>

<complexType name="fullContainer">
  <sequence minOccurs="0" maxOccurs="unbounded">
    <choice minOccurs="0" maxOccurs="1">
      <element ref="w:aTag0"/>
      <element ref="w:aTag1"/>
      <element ref="w:aTag2"/>
      <element ref="w:aTag3"/>
      <element ref="w:aTag4"/>
    </choice>
  </sequence>
</complexType>

I have tried this:

<complexType name="fullContainer">
  <complexContent>
    <extension base="w:baseContainer">
      <sequence minOccurs="0" maxOccurs="unbounded">
        <choice minOccurs="0" maxOccurs="1">
          <element ref="w:aTag3"/>
          <element ref="w:aTag4"/>
        </choice>
      </sequence>
    </extension>
  </complexContent>
</complexType>
A: 

As far a I know, what you want is not possible in xml-schema. You can extend (or restrict) a defined type. But you cannot extend a choice element.

Hans van Dodewaard
Is there another way to describe a element which can contain multiple unordered elements? I know there is the <all> tag but as far as I know, it can't be used when it is multiple optional elements
lasseespeholt
Hans is right about this; you cannot restrict any particle (all, choice, etc). There is no way to extend a collection of unordered elements.You might try defining your main type as containing xsd:any and then validating some other way.
xcut