title: XML validation failing in java with schemaLocation a local file
body: <p>I'm attempting to validate some XML against a relative XSD file in java</p>
  
  <p>input file temp.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;tagname:b
          xmlns:tagname="http://my_namespace.org/v1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://my_namespace.org/v1 ./local_xsd_file.xsd"&gt;
  &lt;/tagname&gt;
  </code></pre>
  
  <p>java source:</p>
  
  <pre><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setValidating(true);
  factory.setNamespaceAware(true);
  factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
  DocumentBuilder builder = factory.newDocumentBuilder();
  builder.setErrorHandler(new RaiseOnErrorHandler());
  builder.parse(new InputSource(new FileInputStream(filename)));
  
  public static class RaiseOnErrorHandler implements ErrorHandler {
    public void warning(SAXParseException e) throws SAXException {
      throw new RuntimeException(e);
    }
    public void error(SAXParseException e) throws SAXException {
      throw new RuntimeException(e);
    }
    public void fatalError(SAXParseException e) throws SAXException {
      throw new RuntimeException(e);
    }
  }
  </code></pre>
  
  <p>The local file <code>local_xsd_file.xsd</code> exists and appears to be not being read.</p>
  
  <p>error message </p>
  
  <pre><code>java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 85; schema_reference.4: Failed to read schema document './local_xsd_file.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;.
      at org.XX$RaiseOnErrorHandler.warning(DigitalFileWriterTest.java:1114)
      at org.apache.xerces.util.ErrorHandlerWrapper.warning(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
      at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaWarning(Unknown Source)
      at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
      at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
      at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
      at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
      at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
      ... 50 more
  </code></pre>
  
  <p>I have also tried using <code>file://local_xsd_file.xsd</code> and <code>file://./local_xsd_file.xsd</code> (which <a href="https://stackoverflow.com/a/14711665/32453">should</a> be <a href="https://stackoverflow.com/a/4856489/32453">possible</a>) as the <code>schemaLocation</code>, all with the same results.  If I use an "absolute path" like <code>file:///full/path/to/local_xsd_file.xsd</code> then it works.  If I use a URL for the schema's location it reads them off that server and works fine.</p>
  
  <p>Changing my current working directory to be one where a local_xsd_file.xsd exists will make it work, so apparently this works but only relative to your current working directory?</p>
  
  <p>Is it possible to use a relative path with validation in java?  It feels like an implementation detail perhaps?</p>