private static final void prettyPrint(Node xml,OutputStream out) throws Exception {
  TransformerFactory tFactory=TransformerFactory.newInstance();
  Transformer tf=tFactory.newTransformer();
  tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes");
  tf.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
  tf.setOutputProperty(OutputKeys.INDENT,"yes");
  tf.setOutputProperty(OutputKeys.METHOD,"xml");
  tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","5");
  StreamResult result=new StreamResult(new OutputStreamWriter(out,"UTF-8"));
  tf.transform(new DOMSource(xml),result);
}

private static final void prettyPrint ( Node xml , OutputStream out ) throws Exception { TransformerFactory tFactory = TransformerFactory . newInstance ( ) ; Transformer tf = tFactory . newTransformer ( ) ; tf . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , "yes" ) ; tf . setOutputProperty ( OutputKeys . ENCODING , "UTF-8" ) ; tf . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; tf . setOutputProperty ( OutputKeys . METHOD , "xml" ) ; tf . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , "5" ) ; StreamResult result = new StreamResult ( new OutputStreamWriter ( out , "UTF-8" ) ) ; tf . transform ( new DOMSource ( xml ) , result ) ; }
print out xml node to a stream
