title: How to validate XML elements with XSD schema?
body: <p>I would like to use conditions in my XSD schema for my XML document.</p>
  
  <p>I used restrictions but it's not quite powerful.</p>
  
  <p>Here is an example of what I did so far:</p>
  
  <pre><code>&lt;xs:element name="Matricule"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="valeur"&gt;
                      &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:integer"&gt;
                              &lt;xs:minInclusive value="0"&gt;&lt;/xs:minInclusive&gt;
                          &lt;/xs:restriction&gt;
                      &lt;/xs:simpleType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element type="xs:string" name="backgroundcolor"/&gt;
                &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
  </code></pre>
  
  <p>This example works fine but I check just if the value is greater than 0. But I would like to verify if the value is an Integer AND if the value is empty.</p>
  
  <p>Maybe something like that:</p>
  
  <blockquote>
    <p>If (value > 0 AND value &lt; 100 AND value = '')</p>
  </blockquote>
  
  <p>I found on Google a subject who calls about assertion, so I read the document and I did that</p>
  
  <pre><code>&lt;xs:element name="Matricule"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="valeur"&gt;
                      &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:integer"&gt;
                              &lt;xs:minInclusive value="0"&gt;&lt;/xs:minInclusive&gt;
                              **&lt;xs:assertion test="($value mod 10) = 0"/&gt;**
                          &lt;/xs:restriction&gt;
                      &lt;/xs:simpleType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element type="xs:string" name="backgroundcolor"/&gt;
                &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
  </code></pre>
  
  <p>But it doesn't work, I always have an error.</p>
  
  <p>Exemple 1 with value :</p>
  
  <pre><code>&lt;racine&gt;
    &lt;row&gt;
      &lt;Matricule&gt;
        &lt;valeur&gt;55&lt;/valeur&gt;
        &lt;backgroundcolor&gt;&lt;/backgroundcolor&gt;
      &lt;/Matricule&gt;
    &lt;/row&gt;
  &lt;/racine&gt; 
  </code></pre>
  
  <p>Exemple 2 without value :</p>
  
  <pre><code>&lt;racine&gt;
    &lt;row&gt;
      &lt;Matricule&gt;
        &lt;valeur&gt;&lt;/valeur&gt;
        &lt;backgroundcolor&gt;&lt;/backgroundcolor&gt;
      &lt;/Matricule&gt;
    &lt;/row&gt;
  &lt;/racine&gt;
  </code></pre>
  
  <p>These two examples need to be correct but this one no :</p>
  
  <pre><code>&lt;racine&gt;
    &lt;row&gt;
      &lt;Matricule&gt;
        &lt;valeur&gt;gfd&lt;/valeur&gt;
        &lt;backgroundcolor&gt;&lt;/backgroundcolor&gt;
      &lt;/Matricule&gt;
    &lt;/row&gt;
  &lt;/racine&gt;
  </code></pre>