Java tutorial
//package com.java2s; import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; 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) throws TransformerFactoryConfigurationError, TransformerException { String serializedElement = null; if (element != null) { StringWriter output = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(element), new StreamResult(output)); serializedElement = output.toString(); } return serializedElement; } }