Here you can find the source of asXmlString(Node node)
public static String asXmlString(Node node) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static String asXmlString(Node node) throws IOException { final Source source = new DOMSource(node); final StringWriter stringWriter = new StringWriter(); final Result result = new StreamResult(stringWriter); final TransformerFactory factory = TransformerFactory.newInstance(); try {/* w w w .j av a 2 s . c om*/ final Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (TransformerException exc) { throw new IOException(exc.getMessage(), exc); } } }