title: Xerces XML validation with XSD
body: <p>I try to validate XML file using a given XSD grammar file. But for now it always return error saying <code>no  declaration found for element ...</code> and that for each element or attribute I have in my XML file.</p>
  
  <p>To create the XSD i used that <a href="http://www.freeformatter.com/xsd-generator.html" rel="nofollow">Free online XSD generator</a> and if I check my xml within that XSD using the (Validator)[http://www.freeformatter.com/xml-validator-xsd.html] on the same site, everything looks fine. </p>
  
  <p>So why Xerces fails ?</p>
  
  <p>I use the following code to validate:</p>
  
  <pre><code>      XercesDOMParser domParser;
        if (domParser.loadGrammar(schemaFilePath.c_str(), Grammar::SchemaGrammarType) == NULL)
        {
          throw Except("couldn't load schema");
        }
  
        ParserErrorHandler parserErrorHandler;
  
        domParser.setErrorHandler(&amp;parserErrorHandler);
        domParser.setValidationScheme(XercesDOMParser::Val_Always);
        domParser.setDoNamespaces(true);
        domParser.setDoSchema(true);
        domParser.setValidationSchemaFullChecking(true);
  
        domParser.parse(xmlFilePath.c_str());
        if(domParser.getErrorCount() != 0)
        {     
          throw Except("Invalid XML vs. XSD: " + parserErrorHandler.getErrors()); //merge a error coming from my interceptor ....
        }
  </code></pre>
  
  <p>My XML test file is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;schemes signature="9fadde05"&gt;
      &lt;!-- NOTE: Do not modify this file. 
       Any modifications will invalidate the signature and result in an invalid file! 
       This is an example scheme, param_set etc... can be rename / market or / product
      --&gt;
      &lt;scheme&gt;
          &lt;name&gt;test1&lt;/name&gt;
          &lt;other&gt;test2&lt;/other&gt;
      &lt;/scheme&gt;
      &lt;param_set&gt;
          &lt;input&gt;
              &lt;height min="1060" max="1100" /&gt;
              &lt;width min="1900" max="1940" /&gt;
          &lt;/input&gt;
      &lt;/param_set&gt;
  &lt;/schemes&gt;
  </code></pre>
  
  <p>And the XSD I use is:</p>
  
  <pre><code>&lt;xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="schemes"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="scheme"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element type="xs:string" name="name"/&gt;
                &lt;xs:element type="xs:string" name="other"/&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
          &lt;xs:element name="param_set"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="input"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="height"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:simpleContent&gt;
                            &lt;xs:extension base="xs:string"&gt;
                              &lt;xs:attribute type="xs:short" name="min"/&gt;
                              &lt;xs:attribute type="xs:short" name="max"/&gt;
                            &lt;/xs:extension&gt;
                          &lt;/xs:simpleContent&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                      &lt;xs:element name="width"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:simpleContent&gt;
                            &lt;xs:extension base="xs:string"&gt;
                              &lt;xs:attribute type="xs:short" name="min"/&gt;
                              &lt;xs:attribute type="xs:short" name="max"/&gt;
                            &lt;/xs:extension&gt;
                          &lt;/xs:simpleContent&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
        &lt;xs:attribute type="xs:string" name="signature"/&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>