Dump XML in Java

In this example, node is the XML node (which can be a document) you want to dump. You’ll see the XML in System.out. If you like the output in a String (e.g. for logging), use a StringWriter as the output.


Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.transform(new DOMSource(node), new StreamResult(System.out));

Leave a Reply