title: how to marshal a JAXB object to org.w3c.dom.Document?
body: <p>This gives me a Document object with a top level node with no child nodes:</p>
  
  <pre><code>public static Document getDocument(Object jaxb)
  {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      //dbf.setNamespaceAware(true);
      Document doc = dbf.newDocumentBuilder().newDocument(); 
  
      JAXBContext context = JAXBContext.newInstance(jaxb.getClass());
      context.createMarshaller().marshal(jaxb, doc);
  
      return doc;
  }
  </code></pre>
  
  <p>This is the workaround, which seems even more inefficient, since it converts to String and then to Document.</p>
  
  <pre><code>public static Document getDocument(Object jaxb)
  {                           
      StringWriter writer = new StringWriter();       
      JAXBContext context = JAXBContext.newInstance(jaxb.getClass());
      context.createMarshaller().marshal(jaxb, writer);
  
      return DocumentBuilderFactory.newInstance().newDocumentBuilder().
  parse(new InputSource(new StringReader(writer.toString()));
  }
  </code></pre>
  
  <p>Is it possible to accomplish what I'm trying to accomplish?</p>