title: Unmarshall xml using Document instead of StreamSource
body: <p>I previously unmarshaled my documents with this Method from "javax.xml.bind.Unmarshaller" (i am using Moxy as jaxb provider):</p>
  
  <pre><code>&lt;Object&gt; JAXBElement&lt;Object&gt; javax.xml.bind.Unmarshaller.unmarshal(Source source, Class&lt;Object&gt; declaredType) throws JAXBException
  </code></pre>
  
  <p>Now i have to refactor my code to use</p>
  
  <pre><code>&lt;?&gt; JAXBElement&lt;?&gt; javax.xml.bind.Unmarshaller.unmarshal(Node node, Class&lt;?&gt; declaredType) throws JAXBException
  </code></pre>
  
  <p>The problem is that i get an unmarshal exception:</p>
  
  <pre><code>    Caused by: javax.xml.bind.UnmarshalException
   - with linked exception:
  [Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.XMLMarshalException
  Exception Description: An error occurred unmarshalling the document
  Internal Exception: org.xml.sax.SAXParseExceptionpublicId: ; systemId: ; lineNumber: 0; columnNumber: 0; cvc-elt.1: Cannot find the declaration of element 'invoice:request'.]
  </code></pre>
  
  <p>i tried unmarshal with Document and with Document.getDocumentElement(). The data in document is the same as in InputStream. Document is created this way:</p>
  
  <pre><code>    protected static Document extractDocument(InputStream sourceData) {
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      Document doc;
      try {
          DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
          doc = docBuilder.parse(new InputSource(sourceData));
      } catch (Exception e) {
          throw new IllegalArgumentException("Problem on reading xml, cause: ", e);
      }
      return doc;
  }
  </code></pre>
  
  <p>I need the "intermediate" Document to do the type recognition/ to get the second argument for unmarshal.</p>
  
  <p>so how to use the unmarshal method with Node/Document that the outcome is the same as used with the inputstream?</p>
  
  <p><strong>Edit for rick</strong></p>
  
  <p>I am unmarshalling xml data from <a href="http://www.forum-datenaustausch.ch/xmlstandards/xml_4.3/xml_rechnung_xml_4.3/xml_rechnung_generelle_rechnung_xml_4.3" rel="nofollow">here</a> xsds are in <a href="http://www.forum-datenaustausch.ch/generalinvoicerequest_430.xsd.zip" rel="nofollow">this zip</a> and examples are <a href="http://www.forum-datenaustausch.ch/xmlstandards_generelle_rechnung_beispiele_anfrage_4.3_20100901.zip" rel="nofollow">here</a>.</p>
  
  <p>i wrote a simple test (jaxb provider is moxy, it was also used to generate the binding classes):</p>
  
  <pre><code>    @Test
  public void test() throws Exception {
      Unmarshaller um;
      JAXBContext jaxbContext = JAXBContext
              .newInstance("....generatedClasses.invoice.general430.request");
      um = jaxbContext.createUnmarshaller();
  
      InputStream xmlIs = SingleTests.class.getResourceAsStream("/430_requests/dentist_ersred_TG_430.xml");
  
      SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema schema = sf.newSchema(this.getClass().getResource("/xsd/" + "generalInvoiceRequest_430.xsd"));
      // start
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      Document doc;
      try {
          DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
          doc = docBuilder.parse(new InputSource(xmlIs));
      } catch (Exception e) {
          throw new Exception("Problem on recognizing invoice type of given xml, cause: ", e);
      }
      // end
      um.setSchema(schema);
      um.unmarshal(doc, ....generatedClasses.invoice.general430.request.RequestType.class);
  
  }
  </code></pre>
  
  <p>This is not working with the error described above. But as soon as deleted the "start end block" and unmarshall the stream xmlIs directly (not using the Document) the code works.</p>