title: How to validate an XML file using Java with an XSD having an include?
body: <p>I'm using Java 5 javax.xml.validation.Validator to validate XML file. I've done it for one schema that uses only imports and everything works fine. Now I'm trying to validate with another schema that uses import and one include. The problem I have is that element in the main schema are ignored, the validation says it cannot find their declaration. </p>
  
  <p>Here is how I build the Schema:</p>
  
  <pre><code>InputStream includeInputStream = getClass().getClassLoader().getResource("include.xsd").openStream();
  InputStream importInputStream = getClass().getClassLoader().getResource("import.xsd").openStream();
  InputStream mainInputStream = getClass().getClassLoader().getResource("main.xsd").openStream();
  Source[] sourceSchema = new SAXSource[]{includeInputStream , importInputStream, 
  mainInputStream };
  Schema schema = factory.newSchema(sourceSchema);
  </code></pre>
  
  <p>Now here is the extract of the declaration in main.xsd</p>
  
  <pre><code>&lt;xsd:schema xmlns="http://schema.omg.org/spec/BPMN/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import="http://www.foo.com/import" targetNamespace="http://main/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
      &lt;xsd:import namespace="http://www.foo.com/import" schemaLocation="import.xsd"/&gt;
      &lt;xsd:include schemaLocation="include.xsd"/&gt;
      &lt;xsd:element name="element" type="tElement"/&gt;
      &lt;...&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>If I copy the code of my included XSD in the main.xsd, it works fine. If I don't, validation doesn't find the declaration of "Element".</p>