Here you can find the source of domNodeListToString(NodeList nodeList)
public static String domNodeListToString(NodeList nodeList) throws TransformerException
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; import org.w3c.dom.NodeList; 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 java.io.StringWriter; public class Main { public static String domNodeListToString(NodeList nodeList) throws TransformerException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); sb.append(domNodeToString(node)); // Below formatting will cause xpath assertion verification failure when // xpath evaluation result is of type NODESET. //sb.append(System.getProperty("line.separator")); }/*from ww w . j a v a2s .c om*/ return sb.toString(); } public static String domNodeToString(Node node) throws TransformerException { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } }