title: Cannot validate xml doc against a xsd schema (Cannot find the declaration of element 'replyMessage')
body: <p>I am using the following code to validate an an XML file against a XSD schema</p>
  
  <pre><code>package com.forat.xsd;
  
  import java.io.IOException;
  import java.net.URL;
  
  import javax.xml.XMLConstants;
  import javax.xml.transform.Source;
  import javax.xml.transform.stream.StreamSource;
  import javax.xml.validation.Schema;
  import javax.xml.validation.SchemaFactory;
  import javax.xml.validation.Validator;
  
  import org.xml.sax.ErrorHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException;
  
  public class XSDValidate {
  
   public void validate(String xmlFile, String xsd_url) {
    try {
     SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
     Schema schema = factory.newSchema(new URL(xsd_url));
     Validator validator = schema.newValidator();
     ValidationHandler handler = new ValidationHandler();
     validator.setErrorHandler(handler);
     validator.validate(getSource(xmlFile));
  
     if (handler.errorsFound == true) {
      System.err.println("Validation Error : "+ handler.exception.getMessage());
     }else {
      System.out.println("DONE");
     }
    } catch (SAXException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  
   private Source getSource(String resource) {
    return new StreamSource(XSDValidate.class.getClassLoader().getResourceAsStream(resource));
   }
  
   private class ValidationHandler implements ErrorHandler {
    private boolean errorsFound = false;
    private SAXParseException exception;
  
    public void error(SAXParseException exception) throws SAXException {
     this.errorsFound = true;
     this.exception = exception;
    }
  
    public void fatalError(SAXParseException exception) throws SAXException {
     this.errorsFound = true;
     this.exception = exception;
    }
  
    public void warning(SAXParseException exception) throws SAXException {
    }
   }
  
   /*
    * Test
    */
   public static void main(String[] args) {
    new XSDValidate().validate("com/forat/xsd/reply.xml", 
      "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.53.xsd"); // return error
   }
  
  }
  </code></pre>
  
  <p>As appears, It is a standard code that try to validate the following XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;replyMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
   &lt;merchantReferenceCode&gt;XXXXXXXXXXXXX&lt;/merchantReferenceCode&gt;
   &lt;requestID&gt;XXXXXXXXXXXXX&lt;/requestID&gt;
   &lt;decision&gt;XXXXXXXXXXXXX&lt;/decision&gt;
   &lt;reasonCode&gt;XXXXXXXXXXXXX&lt;/reasonCode&gt;
   &lt;requestToken&gt;XXXXXXXXXXXXX
   &lt;/requestToken&gt;
   &lt;purchaseTotals&gt;
    &lt;currency&gt;XXXXXXXXXXXXX&lt;/currency&gt;
   &lt;/purchaseTotals&gt;
   &lt;ccAuthReply&gt;
    &lt;reasonCode&gt;XXXXXXXXXXXXX&lt;/reasonCode&gt;
    &lt;amount&gt;XXXXXXXXXXXXX&lt;/amount&gt;
    &lt;authorizationCode&gt;XXXXXXXXXXXXX&lt;/authorizationCode&gt;
  
    &lt;avsCode&gt;XXXXXXXXXXXXX&lt;/avsCode&gt;
    &lt;avsCodeRaw&gt;XXXXXXXXXXXXX&lt;/avsCodeRaw&gt;
    &lt;authorizedDateTime&gt;XXXXXXXXXXXXX&lt;/authorizedDateTime&gt;
    &lt;processorResponse&gt;0XXXXXXXXXXXXX&lt;/processorResponse&gt;
    &lt;authRecord&gt;XXXXXXXXXXXXX
    &lt;/authRecord&gt;
   &lt;/ccAuthReply&gt;
  &lt;/replyMessage&gt;
  </code></pre>
  
  <p>Against the following XSD:</p>
  
  <p><a href="https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.53.xsd" rel="nofollow noreferrer">https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.53.xsd</a></p>
  
  <p>The error is :</p>
  
  <blockquote>
    <p>Validation Error : cvc-elt.1: Cannot find the declaration of element 'replyMessage'.</p>
  </blockquote>