Here you can find the source of serializeToString(org.w3c.dom.Document doc)
public static String serializeToString(org.w3c.dom.Document doc)
//package com.java2s; /*/*from w w w. j a v a 2s . co m*/ * Copyright (c) 2012. betterFORM Project - http://www.betterform.de * Licensed under the terms of BSD License */ import javax.xml.transform.OutputKeys; 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 java.io.*; public class Main { public static String serializeToString(org.w3c.dom.Document doc) { try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "no"); transformer.transform(domSource, result); writer.flush(); return writer.toString(); } catch (TransformerException ex) { ex.printStackTrace(); return null; } } }