Java tutorial
//package com.java2s; //License from project: Apache License import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { /** * XSL transform (identity) to create text from Document. */ static private Transformer identityTransformer; static public String document2String(Node document) { if (document == null) return null; StringWriter stringWriter = new StringWriter(); try { identityTransformer.transform(new DOMSource(document), new StreamResult(stringWriter)); } catch (TransformerException e) { e.printStackTrace(); } return stringWriter.toString(); } }