title: How do I validate an XML with a schema file that imports another schema file?
body: <p>I want to validate XML files against <a href="http://www.forum-datenaustausch.ch/generalinvoicerequest_430.xsd.zip" rel="nofollow noreferrer">this schema</a> (that is inside the zip); it imports two other XSD files.</p>
  
  <pre><code>   &lt;import namespace="http://www.w3.org/2000/09/xmldsig#" 
         schemaLocation="xmldsig-core-schema.xsd"/&gt;
     &lt;import namespace="http://www.w3.org/2001/04/xmlenc#" 
         schemaLocation="xenc-schema.xsd"/&gt;
  </code></pre>
  
  <p>The 2 files are also available here: </p>
  
  <ul>
  <li><a href="http://www.forum-datenaustausch.ch/xmldsig-core-schema.zip" rel="nofollow noreferrer">http://www.forum-datenaustausch.ch/xmldsig-core-schema.zip</a></li>
  <li><a href="http://www.forum-datenaustausch.ch/xenc-schema.zip" rel="nofollow noreferrer">http://www.forum-datenaustausch.ch/xenc-schema.zip</a>.</li>
  </ul>
  
  <p>On validation, I get this error:</p>
  
  <pre><code>Src-resolve: Cannot Resolve The Name 'xenc:EncryptedData' To A(n) 'element Declaration' Component.
  </code></pre>
  
  <p>My validation/unmarshalling code looks like this (using moxy as a JAXB provider):</p>
  
  <pre><code>jaxbContext = JAXBContext.newInstance(type.getRequestType().getPackage().getName());
  Unmarshaller um = jaxbContext.createUnmarshaller();
  
  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = sf.newSchema(new StreamSource(this.getClass().getResourceAsStream("/xsd/" + type.getXsdName())));
  um.setSchema(schema);
  
  root = um.unmarshal(new StreamSource(new ByteArrayInputStream(xmlData)), type.getRequestType());
  </code></pre>
  
  <p>Before you ask what does the type do: I wrote code that could import all types of invoices from <a href="http://www.forum-datenaustausch.ch/" rel="nofollow noreferrer">http://www.forum-datenaustausch.ch/</a>. But versions 4.3 and above use the two additional schema files. How can validate the XML files?</p>