title: Problem validating XSD with 'choice' and 'extension' elements
body: <p>I will post two examples, one that validates and one that doesn't.  I am interested in learning why the second one doesn't work since they are very similar.</p>
  <p><strong>Example 1</strong> (validates)</p>
  <p><strong>xsd:</strong></p>
  <pre><code>&lt;xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; &gt;
    &lt;xsd:element name=&quot;root&quot; type=&quot;BBB&quot;/&gt;
      &lt;xsd:complexType name=&quot;AAA&quot;&gt;
        &lt;xsd:choice maxOccurs=&quot;2&quot;&gt;
          &lt;xsd:element name=&quot;x&quot; type=&quot;xsd:string&quot;/&gt;
          &lt;xsd:element name=&quot;y&quot; type=&quot;xsd:string&quot;/&gt;
        &lt;/xsd:choice&gt;
      &lt;/xsd:complexType&gt;
    &lt;xsd:complexType name=&quot;BBB&quot;&gt;
      &lt;xsd:complexContent&gt;
        &lt;xsd:extension base=&quot;AAA&quot;/&gt;
      &lt;/xsd:complexContent&gt;
    &lt;/xsd:complexType&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  <p><strong>xml:</strong></p>
  <pre><code>&lt;root xsi:noNamespaceSchemaLocation=&quot;incorrect.xsd&quot; xmlns=&quot;&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; &gt;
     &lt;x&gt;1&lt;/x&gt;
     &lt;y&gt;1&lt;/y&gt;
  &lt;/root&gt;
  </code></pre>
  <p><strong>Example 2</strong> (does not validate)</p>
  <p><strong>xsd:</strong></p>
  <pre><code>&lt;xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; &gt;
     &lt;xsd:element name=&quot;root&quot; type=&quot;BBB&quot;/&gt;
     &lt;xsd:complexType name=&quot;AAA&quot;&gt;
        &lt;xsd:choice maxOccurs=&quot;2&quot;&gt;
           &lt;xsd:element name=&quot;x&quot; type=&quot;xsd:string&quot;/&gt;
           &lt;xsd:element name=&quot;y&quot; type=&quot;xsd:string&quot;/&gt;
        &lt;/xsd:choice&gt;
     &lt;/xsd:complexType&gt;
     &lt;xsd:complexType name=&quot;BBB&quot;&gt;
        &lt;xsd:complexContent&gt;
           &lt;xsd:extension base=&quot;AAA&quot;&gt;
              &lt;xsd:choice&gt;
                 &lt;xsd:element name=&quot;z&quot; type=&quot;xsd:string&quot;/&gt;
              &lt;/xsd:choice&gt;
           &lt;/xsd:extension&gt;
        &lt;/xsd:complexContent&gt;
     &lt;/xsd:complexType&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  <p><strong>xml:</strong> (the same as Example 1)</p>
  <pre><code>&lt;root xsi:noNamespaceSchemaLocation=&quot;incorrect.xsd&quot; xmlns=&quot;&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; &gt;
     &lt;x&gt;1&lt;/x&gt;
     &lt;y&gt;1&lt;/y&gt;
  &lt;/root&gt;
  </code></pre>
  <p>To save you the time running the diff against the xsd's, the only difference is that in the second example complex type BBB has a <code>&lt;choice&gt;</code></p>
  <p><em>xmllint</em> says the following about Example 2:</p>
  <blockquote>
  <p>$ xmllint --noout --schema example2.xsd example2.xml</p>
  <p>example2.xml:3: element y: Schemas validity error : Element 'y': This element is not expected. Expected is ( z ).</p>
  <p>example2.xml fails to validate</p>
  </blockquote>
  <hr />
  <p>Examples loosely based off of <a href="http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_ext_patterns_st1.html" rel="nofollow noreferrer">http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_ext_patterns_st1.html</a></p>