Here you can find the source of serializeElement(Element element, boolean omitXmlDeclaration, boolean indent, String method)
public static String serializeElement(Element element, boolean omitXmlDeclaration, boolean indent, String method) throws TransformerException
//package com.java2s; //License from project: Open Source License import java.io.StringWriter; 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 org.w3c.dom.Element; public class Main { public static String serializeElement(Element element, boolean omitXmlDeclaration, boolean indent, String method) throws TransformerException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration ? "yes" : "no"); transformer.setOutputProperty(OutputKeys.METHOD, method); transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(element), new StreamResult(writer)); return writer.getBuffer().toString(); }/*from w w w. j a v a 2s .co m*/ }