code: public static String getXml(Node node, boolean indentXml, int indentSize) {
      	try {
  			TransformerFactory tf = TransformerFactory.newInstance();
  			Transformer transformer;
  			
  			if (indentXml) {
  				transformer = tf.newTransformer();
  				transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  				transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", new Integer(indentSize).toString());
  			} else {
  				transformer = tf.newTransformer(new StreamSource(XPathUtil.class.getResourceAsStream("remove-whitespace.xsl")));
  			}
  			
  			//initialize StreamResult with File object to save to file
  			StreamResult result = new StreamResult(new StringWriter());
  			DOMSource source = new DOMSource(node);
  			transformer.transform(source, result);
  
  			String xmlString = result.getWriter().toString();
  			return xmlString;
  		} catch (Exception e) {
  			throw new RuntimeException(e);
  		}
      }
docs: Creates a string representation of the dom node.
  NOTE: The string can be formatted and indented with a specified indent size, but be aware that this is depending on a Xalan implementation of the XSLT library.
  
  @param node
  @param indentXml
  @param indentSize
  @return