What I want to do is create a sequence element in an XML schema such that the contents must be in order, but may not all be present. For example, the schema would be something like this:
<xs:element name="rods" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="green" type="xs:positiveInteger" />
<xs:element name="white" type="xs:positiveInteger" />
<xs:element name="blue" type="xs:positiveInteger" />
<xs:element name="yellow" type="xs:positiveInteger" />
<xs:element name="red" type="xs:positiveInteger" />
<xs:element name="tan" type="xs:positiveInteger" />
<xs:element name="gray" type="xs:positiveInteger" />
<xs:element name="black" type="xs:positiveInteger" />
</xs:sequence>
</xs:complexType>
</xs:element>
and would allow XML like this:
<rods>
<green>142</green>
<white>34</white>
<gray>65</gray>
</rods>
MSDN has this to say about it:
The following example shows an element (zooAnimals) that can have zero or more of the following elements, elephant, bear, giraffe, in the sequence element.
<xs:element name="zooAnimals"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element name="elephant"/> <xs:element name="bear"/> <xs:element name="giraffe"/> </xs:sequence> </xs:complexType> </xs:element>
W3Schools suggests the same. However, both visual studio and an online validation service don't like what is suggested.
Here is what I have at the moment:
<xs:element name="rods" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element name="green" type="xs:positiveInteger" />
<xs:element name="white" type="xs:positiveInteger" />
<xs:element name="blue" type="xs:positiveInteger" />
<xs:element name="yellow" type="xs:positiveInteger" />
<xs:element name="red" type="xs:positiveInteger" />
<xs:element name="tan" type="xs:positiveInteger" />
<xs:element name="gray" type="xs:positiveInteger" />
<xs:element name="black" type="xs:positiveInteger" />
</xs:sequence>
</xs:complexType>
</xs:element>
And here's the XML:
<rods>
<green>142</green>
<white>34</white>
<gray>65</gray>
</rods>
Visual Studio 2005 claims that "gray" is invalid, "blue" expected, so clearly it wants all of the children
Thanks,
Eric