title: Why is my xsd:choice between elements of different types failing?
body: <p>I'm trying to validate an XML with XSD, but I can't understand what is wrong with my XSD.</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Grades xs:noNamespaceSchemaLocation="grade.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;Grade description="Pass"&gt;
          &lt;LetterGrade&gt;A+&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;4.00&lt;/GradePoint&gt;
          &lt;Percentage&gt;80% and above&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Pass"&gt;
          &lt;LetterGrade&gt;A&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;4.00&lt;/GradePoint&gt;
          &lt;Percentage&gt;70% to 80%&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Pass"&gt;
          &lt;LetterGrade&gt;B&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;3.00&lt;/GradePoint&gt;
          &lt;Percentage&gt;60% to 70%&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Pass"&gt;
          &lt;LetterGrade&gt;C&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;2.00&lt;/GradePoint&gt;
          &lt;Percentage&gt;50% to 60%&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Pass"&gt;
          &lt;LetterGrade&gt;D&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;1.00&lt;/GradePoint&gt;
          &lt;Percentage&gt;40% to 50%&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Fail"&gt;
          &lt;LetterGrade&gt;F&lt;/LetterGrade&gt;
          &lt;GradePoint&gt;0&lt;/GradePoint&gt;
          &lt;Percentage&gt;Below 40%&lt;/Percentage&gt;
      &lt;/Grade&gt;
      &lt;Grade description="Incomplete"&gt; Incomplete module/project/independent study due
      to medical/financial/other reasons (may be in 1 or both components of the module).
          &lt;LetterGrade&gt;N&lt;/LetterGrade&gt;
      &lt;/Grade&gt;
  &lt;/Grades&gt;
  </code></pre>
  
  <p><strong>XSD</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
  &lt;xs:complexType name="gradeDetails"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="LetterGrade" type="xs:string"/&gt;
          &lt;xs:element name="GradePoint" type="xs:decimal"/&gt;
          &lt;xs:element name="Percentage" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name="description" type="xs:string"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="gradeNode"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="LetterGrade" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name="description" type="xs:string"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:element name="Grades"&gt;
      &lt;xs:complexType mixed="true"&gt;
          &lt;xs:choice&gt;
              &lt;xs:element name="Grade" type="gradeDetails" minOccurs="1" maxOccurs="unbounded"/&gt;
              &lt;xs:element name="Grade" type="gradeNode" minOccurs="1" maxOccurs="unbounded"/&gt;
          &lt;/xs:choice&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I tried validating it with the online validator xmlvalidation.com and I'm getting these errors:</p>
  
  <blockquote>
    <p>Errors in the XML document: 
        <br/>36:    10  cvc-complex-type.2.3: Element 'Grade' cannot have character [children], because the type's content type is element-only.
        <br/>36:    10  cvc-complex-type.2.4.b: The content of element 'Grade' is not complete. One of '{"":GradePoint}' is expected.</p>
  </blockquote>
  
  <p>Somewhat, I understood these error messages. I know it's because there are elements missing in the last <code>&lt;Grade&gt;</code> tag. And to solve it I created 2 global types and used choice. What is wrong with it now?</p>