List of usage examples for org.w3c.dom.ls LSOutput getCharacterStream
public java.io.Writer getCharacterStream();
From source file:Main.java
public static final String prettyPrint(final Document aNode) throws Exception { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impls = (DOMImplementationLS) registry.getDOMImplementation("LS"); // Prepare the output LSOutput domOutput = impls.createLSOutput(); domOutput.setEncoding(java.nio.charset.Charset.defaultCharset().name()); StringWriter writer = new StringWriter(); domOutput.setCharacterStream(writer); LSSerializer domWriter = impls.createLSSerializer(); DOMConfiguration domConfig = domWriter.getDomConfig(); domConfig.setParameter("format-pretty-print", true); domConfig.setParameter("element-content-whitespace", true); domWriter.setNewLine("\r\n"); domConfig.setParameter("cdata-sections", Boolean.TRUE); // And finaly, write domWriter.write(aNode, domOutput);// ww w . java 2s .c o m return domOutput.getCharacterStream().toString(); }