title: Java XML Schema validation: prefix not bound
body: <p>I have followed <a href="http://www.w3schools.com/schema/schema_example.asp" rel="nofollow noreferrer">this tutorial</a> for validating XML files. But I am receiving exception when validating XML file. What I am doing wrong? My codes:<br/>
  XML schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  
  &lt;!-- definition of simple elements --&gt;
  &lt;xs:element name="first_name" type="xs:string" /&gt;
  &lt;xs:element name="last_name" type="xs:string" /&gt;
  &lt;xs:element name="phone" type="xs:string" /&gt;
  
  &lt;!-- definition of attributes --&gt;
  &lt;xs:attribute name="type" type="xs:string" use="required"/&gt;
  &lt;xs:attribute name="date" type="xs:date" use="required"/&gt;
  
  &lt;!-- definition of complex elements --&gt;
  
  &lt;xs:element name="reporter"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="first_name" /&gt;
              &lt;xs:element ref="last_name" /&gt;
              &lt;xs:element ref="phone" /&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="report"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:attribute ref="type"/&gt;
          &lt;xs:attribute ref="date" /&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="reporter" /&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>XML file to validate:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;report type="5" date="2012-12-14"&gt;
      &lt;reporter&gt;
          &lt;first_name&gt;FirstName&lt;/firstname&gt;
          &lt;last_name&gt;Lastname&lt;/lastname&gt;
          &lt;phone&gt;+xxxxxxxxxxxx&lt;/phone&gt;
      &lt;/reporter&gt;
  &lt;/report&gt;
  </code></pre>
  
  <p>Java source for validating:</p>
  
  <pre><code>import javax.xml.XMLConstants;
  import javax.xml.transform.Source;
  import javax.xml.transform.stream.StreamSource;
  import javax.xml.validation.*;
  import org.xml.sax.SAXException;
  import java.io.*;
  
  public class ProtocolValidator
  {
      public static void main(String [] args) throws Exception
      {
          Source schemaFile = new StreamSource(new File("schema.xsd"));
          Source xmlFile = new StreamSource(new File("test_xml.xml"));
  
          SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          Schema schema = schemaFactory.newSchema(schemaFile);
          Validator validator = schema.newValidator();
  
          try{
              validator.validate(xmlFile);
              System.out.println(xmlFile.getSystemId() + " is valid");
          }
          catch (SAXException e) 
          {
              System.out.println(xmlFile.getSystemId() + " is NOT valid");
              System.out.println("Reason: " + e.getLocalizedMessage());
          }
      }
  }
  </code></pre>
  
  <p>Exception I am receiving:</p>
  
  <pre><code>Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:/root/test/schema.xsd; lineNumber: 4; columnNumber: 50; The prefix "xs" for element "xs:element" is not bound.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)...
  </code></pre>