Here you can find the source of transform(Transformer transformer, Node element)
private static final String transform(Transformer transformer, Node element) throws TransformerException
//package com.java2s; 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 { private static final String transform(Transformer transformer, Node element) throws TransformerException { StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(element); transformer.transform(source, result); String xmlString = result.getWriter().toString(); return xmlString; }/* w ww. j av a2 s . c om*/ }