Here you can find the source of XMLDOMtoString(Document document)
public static String XMLDOMtoString(Document document)
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { public static String XMLDOMtoString(Document document) { String out = null;/*from w w w. j a v a 2 s . c om*/ try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); StringWriter writer = new StringWriter(); Result result = new StreamResult(writer); Source source = new DOMSource(document); transformer.transform(source, result); writer.close(); out = writer.toString(); } catch (Exception e) { System.out.println("ERROR: " + e.getMessage()); } return out; } }