title: XSD 2 elements once, 1 element 1+ any order
body: <p>I am working on an XML Schema that includes 3 elements which can be in <strong>any order</strong>.</p>
  
  <ul>
  <li>Two of them have to appear <strong>exactly once</strong>, </li>
  <li>The third element can appear <strong>once</strong> or <strong>more than once</strong>.  </li>
  <li>All three are required.</li>
  </ul>
  
  <p>In the example below, every bio has ONE <code>favoriteColor</code> and ONE <code>favoriteNumber</code>, and AT LEAST ONE <code>comment</code>.  I would LIKE them to be allowed in any order, (including alternating).</p>
  
  <pre><code>&lt;xs:element name="bio"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="favoriteColor" maxOccurs="1" minOccurs="1"/&gt;
              &lt;xs:element name="favoriteNumber" maxOccurs="1" minOccurs="1"/&gt;
              &lt;xs:element name="comment" maxOccurs="unbounded" minOccurs="1"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Once possible option is <code>&lt;xs:choice&gt;</code>, but it allows only ONE of the options.  It seems unwieldy to list every possible order combination as an alternate sequence: (abc, acb, bac, bca, cab, cba)... and it still doesn't account for the possibility of having comments interspersed between the other two. (e.g. "comment, number, comment, color, comment, comment" should be allowed)</p>
  
  <p><code>&lt;xs:all&gt;</code> would work well, except it only allows a maximum of 1 instance of each.  I need to allow multiple "comment"s.  I could put <code>&lt;xs:element name="comment" maxOccurs="unbounded" minOccurs="0"/&gt;</code> both above and below an "all" tag, but that doesn't work.  See below:</p>
  
  <pre><code>&lt;xs:element name="bio"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="comment" maxOccurs="unbounded" minOccurs="0"/&gt;
              &lt;xs:all&gt; &lt;!-- not allowed here --&gt;
                  &lt;xs:element ref="favoriteColor" maxOccurs="1" minOccurs="1"/&gt;
                  &lt;xs:element ref="favoriteNumber" maxOccurs="1" minOccurs="1"/&gt;
                  &lt;xs:element ref="comment" maxOccurs="1" minOccurs="1"/&gt;
              &lt;/xs:all&gt;
              &lt;xs:element ref="comment" maxOccurs="unbounded" minOccurs="0"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Any suggestions?  There are quite a few questions on this board that pertain to the order of elements in a schema, but I couldn't find any that addressed what I am trying to do (where I have a combination of "only once" and "at least once)."</p>