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
To include this optional field as part of the default XML for a new form, leave the box checked. To exclude it, clear the check box. All of the non-optional elements have a grayed-out check box, meaning you cannot clear the check box.
Using <xsd:choice> in an XSD The element in the root schema has to be optional. Add attribute minOccurs="0" on the element to make it optional.
The sequence element specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.
In the most general sense, XML element order does not matter, unless otherwise specified by the appropriate schema.
<xs:element name="rods">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="green" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="white" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="blue" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="yellow" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="red" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="tan" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="gray" type="xs:positiveInteger" />
<xs:element minOccurs="0" name="black" type="xs:positiveInteger" />
</xs:sequence>
</xs:complexType>
</xs:element>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With