title: cvc-complex-type.3.2.2: Attribute xsi:schemaLocation is not allowed to appear in <people> in Java DOM
body: <p>I am attempting to validate my XML using XSD in Java by using DOM validator.<br>
  Although, manually, I know that the document is indeed valid, DOM validator shouts back at me and says:  </p>
  
  <pre><code>cvc-complex-type.3.2.2: Attribute &lt;xsi:schemaLocation&gt; is not allowed to appear in the element &lt;people&gt;  
  </code></pre>
  
  <p>I have made sure that:<br>
  <code>setNamespaceAware()</code> is set to <code>true</code><br>
  The <code>schemaLanguage</code> property was set before <code>schemaSource</code><br>
  <code>schemaLanguage</code> is set to <code>http://ww.w3.org/2001/XMLSchema</code><br>
  Both the <code>XSD</code> and <code>XML</code> are in the same folder as the <code>.java</code> and <code>.class</code> file  </p>
  
  <h2> SSCCE </h2>  
  
  <pre><code>import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  import javax.xml.parsers.*;
  
  public class DOMValidator {
      String xmlInstance = null;
      String xmlSchema = null;
  
  
      public static void main(String[] args){
          DOMValidator validator = new DOMValidator();
          validator.validateXML("student.xsd",
                                "helloWorld.xml");
      }
  
      public void validateXML(String xsd,String xml){
          xmlSchema = xsd;
          xmlInstance = xml;
          beginValidation();
      }
  
      public void beginValidation(){
          try{
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setNamespaceAware(true);
              factory.setValidating(true);
  
              factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                   "http://www.w3.org/2001/XMLSchema");
              factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
                                   xmlSchema);
  
              ErrorHandler errorHandler = new ErrorHandler();
  
              DocumentBuilder builder = factory.newDocumentBuilder();
              builder.setErrorHandler(errorHandler);
              builder.parse(xmlInstance);
  
              if(errorHandler.errorOccured == true){
                  System.out.println("Document is Invalid.");
                  System.out.println(errorHandler.ex.getMessage());
              }else{
                  System.out.println("Doument is valid");
              }
  
          }catch(ParserConfigurationException e){
              e.printStackTrace();
          }catch(SAXException e){
              e.printStackTrace();
          }catch(Exception e){
              e.printStackTrace();
          }
      }
  
      private class ErrorHandler extends DefaultHandler{
          public SAXParseException ex = null;
          public boolean errorOccured = false;
  
          @Override public void error(SAXParseException ex){
              this.ex = ex;
              errorOccured = true;
          }
  
          @Override public void fatalError(SAXParseException ex){
              this.ex = ex;
              errorOccured = true;
          }
  
          @Override public void warning(SAXParseException ex){
              this.ex = ex;
              errorOccured = true;
          }
      }
  }  
  </code></pre>
  
  <h2> XSD </h2>  
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema"
          xmlns="http://www.cmu.edu/ns/blank"
          targetNamespace="http://www.cmu.edu/ns/blank"
          elementFormDefault="qualified"&gt;  
  </code></pre>
  
  <h2> XML </h2>
  
  <pre><code>&lt;people
      xmlns="http://www.cmu.edu/ns/blank"
      xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd"&gt;  
  </code></pre>
  
  <p><strong>How do I resolve this?</strong></p>