Here you can find the source of createXML(Node doc)
public static String createXML(Node doc)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { public static String createXML(Node doc) { TransformerFactory xff = TransformerFactory.newInstance(); Transformer serializer = null; try {//from www .ja v a2s .com serializer = xff.newTransformer(); } catch (TransformerConfigurationException te) { throw new RuntimeException("Could not create transformer. " + te.getMessage()); } serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://saxon.sf.net/}indent-spaces", "4"); serializer.setOutputProperty(OutputKeys.METHOD, "xml"); OutputStream os = new ByteArrayOutputStream(); try { serializer.transform(new DOMSource(doc), new StreamResult(os)); os.close(); } catch (Exception e) { throw new RuntimeException("Could not create transformer.", e); } return os.toString(); } }