code: public static InputStream toInputStream(Document doc) throws MarshalException {
  
  		Transformer trans;
  
  		try {
  			trans = TRANSFORMER_FACTORY.newTransformer();
  		} catch (TransformerConfigurationException e) {
  			IfmapJLog.error("Oh oh.... [" + e.getMessage() + "]");
  			throw new MarshalException(e.getMessage());
  		}
  
  		ByteArrayOutputStream baos = new ByteArrayOutputStream();
  		Result result = new StreamResult(baos);
  		byte[] marshalled = null;
  
  		doc.setXmlStandalone(true);
  		Source source = new DOMSource(doc);
  
  		try {
  			trans.transform(source, result);
  		} catch (TransformerException e) {
  			IfmapJLog.error("Oh oh.... [" + e.getMessage() + "]");
  			throw new MarshalException(e.getMessage());
  		}
  		try {
  			baos.flush();
  		} catch (IOException e) {
  			IfmapJLog.error("Oh oh.... [" + e.getMessage() + "]");
  			throw new MarshalException(e.getMessage());
  		}
  
  		marshalled = baos.toByteArray();
  
  		return new ByteArrayInputStream(marshalled);
  	}
docs: Marshal a {@link Document} to {@link InputStream}.
  
  @param doc
  @return
  @throws MarshalException