Skip navigation

I wanted to be able to allow complex type to contain any element in any order.

I wanted to basically say: A farm can have any number of <pig> and <sheep>, and you can have them in any order too.

<xs:complexType name="farm">
  <xs:all minOccurs="0" maxOccurs="unbounded">
    <xs:element name="pig" type="PigType" maxOccurs="unbounded" minOccurs="0" />
    <xs:element name="sheep" type="SheepType" maxOccurs="unbounded" minOccurs="0" />
  </xs:all>
<xs:complexType>

But this stupid visual studio schema editor kept on saying that you CANNOT combine maxOccurs=”unbounded” with xs:all.

Reason:

The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once

So what to do? Again the only 3 options are:

ALL: The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once

CHOICE: The <choice> indicator specifies that either one child element or another can occur

SEQUENCE: The <sequence> indicator specifies that the child elements must appear in a specific order:

No, no and NO!!! NONE of these options suit what I want to say.

WHY won’t it let me just say THE ELEMENTS CAN OCCUR IN ANY NUMBER IN ANY ORDER? Shouldn’t there be another option here…

So the answer is to use xs:choice minOccurs=”0″ maxOccurs=”unbounded” on the farm:

<xs:complexType name="farm">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="pig" type="PigType" />
    <xs:element name="sheep" type="SheepType" />
  </xs:choice>
</xs:complexType>

Reference: This post, and same post here as well.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: