Here you can find the source of writeByDom(Node node, Writer writer, int indent)
private static void writeByDom(Node node, Writer writer, int indent) throws IOException
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSSerializer; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.bootstrap.DOMImplementationRegistry; import java.io.IOException; import java.io.Writer; public class Main { private static void writeByDom(Node node, Writer writer, int indent) throws IOException { try {/* ww w . ja va 2 s. c o m*/ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImpLS = (DOMImplementationLS) registry.getDOMImplementation("LS 3.0"); LSOutput output = domImpLS.createLSOutput(); output.setCharacterStream(writer); output.setEncoding("utf-8"); LSSerializer serializer = domImpLS.createLSSerializer(); serializer.setNewLine("\n"); if (indent > 0) { serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); } serializer.write(node, output); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } catch (InstantiationException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } }