title: Validate XML against XSD with SAXParser results in error
body: <p>I have an XML file and a XSD file, I want to validate the XML against the XSD. </p>
  
  <p>But I keep getting the following error:</p>
  
  <pre><code>org.xml.sax.SAXParseException; schema_reference.4: Failed to read schema document '/connector/connector.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not &lt;xsd:schema&gt;.
  </code></pre>
  
  <p>I printed the <code>canonical path</code> to make sure I was trying to use to right file. But it wont work. </p>
  
  <p>The XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
      &lt;Content&gt;
  &lt;commandLine&gt;
  &lt;commandCode&gt;A1&lt;/commandCode&gt;
  &lt;marks&gt;&lt;mark&gt;&lt;code&gt;mail&lt;/code&gt;&lt;value&gt;test@test.com&lt;/value&gt;&lt;/mark&gt;&lt;/marks&gt;
  &lt;customerID&gt;1&lt;/customerID&gt;
  &lt;MessageType&gt;2&lt;/MessageType&gt;
  &lt;/commandLine&gt;
  &lt;Antwoordregel&gt;&lt;/Antwoordregel&gt;
  &lt;/Content&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>XSD:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema id="Message" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
      &lt;xs:element name="Content"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="commandLine" minOccurs="1" maxOccurs="1"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:sequence minOccurs="1" maxOccurs="1"&gt;
                              &lt;xs:element name="commandCode" type="xs:string" minOccurs="1" maxOccurs="1"/&gt;
                              &lt;xs:element name="marks" minOccurs="0" maxOccurs="1"&gt;
                                  &lt;xs:complexType&gt;
                                      &lt;xs:sequence &gt;
                                          &lt;xs:element name="mark" minOccurs="1" maxOccurs="unbounded"&gt;
                                              &lt;xs:complexType&gt;
                                                  &lt;xs:sequence &gt;                                                             
                                                      &lt;xs:element name="code" type="xs:string" minOccurs="1" maxOccurs="1"/&gt;
                                                      &lt;xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"/&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:element name="customerID" type="xs:string" minOccurs="0" maxOccurs="1"/&gt;
                              &lt;xs:element name="MessageType" type="xs:string" minOccurs="0" maxOccurs="1"/&gt;
                          &lt;/xs:sequence&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element name="Antwoordregel" minOccurs="1" maxOccurs="1"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:sequence minOccurs="0" maxOccurs="1"&gt;
                              &lt;xs:element name="resultCode" type="xs:string" minOccurs="0" maxOccurs="1"/&gt;
                              &lt;xs:element name="statusInfo" minOccurs="0" maxOccurs="unbounded"&gt;
                                  &lt;xs:complexType&gt;
                                      &lt;xs:sequence&gt;
                                          &lt;xs:element name="transactionInfo" type="xs:string" minOccurs="1" maxOccurs="1"/&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:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>The code I am using to validate:</p>
  
  <pre><code>static boolean validateAgainstXSD(String xml){
          try{
              File xsd = new File("connector/connector.xsd");
              System.out.println(xsd.getCanonicalPath());
              SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              Schema schema = factory.newSchema(new StreamSource("/connector/connector.xsd"));
  
              System.out.println(schema.toString());
              Validator validator  = schema.newValidator();
              validator.validate(new StreamSource(xml));
              return true;
          }catch(Exception exe){
              exe.printStackTrace();
          return false;
          }
      }
  </code></pre>
  
  <p>It will always return false. I tried to validate the XML with the XSD with an online tool, which can be found here: <a href="http://www.utilities-online.info/xsdvalidation" rel="nofollow">www.utilities-online.info/xsdvalidation</a>. This validator returns:</p>
  
  <pre><code>Not valid.
  Error - Line 2, 122: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 122; cvc-elt.1: Cannot find the declaration of element 'xs:schema'.
  </code></pre>
  
  <p>What can I do to solve this issue?</p>
  
  <p>Any help is appreciated,</p>
  
  <p>Thanks!</p>