title: How can you make a sequence of optional items which must be in order in an XML schema?
body: <p>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:</p>
  
  <pre><code>&lt;xs:element name="rods" maxOccurs="1" minOccurs="1"&gt;
   &lt;xs:complexType&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element name="green" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="white" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="blue" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="yellow" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="red" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="tan" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="gray" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="black" type="xs:positiveInteger" /&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>and would allow XML like this:</p>
  
  <pre><code>&lt;rods&gt;
   &lt;green&gt;142&lt;/green&gt;
   &lt;white&gt;34&lt;/white&gt;
   &lt;gray&gt;65&lt;/gray&gt;
  &lt;/rods&gt;
  </code></pre>
  
  <p>MSDN has this to say about it:</p>
  
  <blockquote>
    <p>The following example shows an element (zooAnimals) that can have zero or more of the following elements, elephant, bear, giraffe, in the sequence element.</p>
  
  <pre><code>&lt;xs:element name="zooAnimals"&gt;
        &lt;xs:complexType&gt;
              &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;
                 &lt;xs:element name="elephant"/&gt;
                 &lt;xs:element name="bear"/&gt;
                 &lt;xs:element name="giraffe"/&gt;
              &lt;/xs:sequence&gt;
        &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  </blockquote>
  
  <p>W3Schools suggests the same.
  However, both visual studio and an online validation service don't like what is suggested.</p>
  
  <p>Here is what I have at the moment:</p>
  
  <pre><code>&lt;xs:element name="rods" maxOccurs="1" minOccurs="1"&gt;
   &lt;xs:complexType&gt;
    &lt;xs:sequence minOccurs="0" maxOccurs="1"&gt;
     &lt;xs:element name="green" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="white" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="blue" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="yellow" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="red" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="tan" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="gray" type="xs:positiveInteger" /&gt;
     &lt;xs:element name="black" type="xs:positiveInteger" /&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>And here's the XML:</p>
  
  <pre><code>&lt;rods&gt;
   &lt;green&gt;142&lt;/green&gt;
   &lt;white&gt;34&lt;/white&gt;
   &lt;gray&gt;65&lt;/gray&gt;
  &lt;/rods&gt;
  </code></pre>
  
  <p>Visual Studio 2005 claims that "gray" is invalid, "blue" expected, so clearly it wants all of the children</p>
  
  <p>Thanks,</p>
  
  <p>Eric</p>