Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Created April 30, 2015 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonashackt/36737ba6c20f2fd35c55 to your computer and use it in GitHub Desktop.
Save jonashackt/36737ba6c20f2fd35c55 to your computer and use it in GitHub Desktop.
org.w3c.dom.Document to String
private void printXML2Console(Node documentOrDocumentFragment)
throws TransformerFactoryConfigurationError,
TransformerConfigurationException,
TransformerException {
DOMSource domSource = new DOMSource(documentOrDocumentFragment);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
System.out.println("XML IN String format is: \n" + writer.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment