Here you can find the source of nodeToString(Node node)
public static String nodeToString(Node node)
//package com.java2s; /*/*from w w w .j a va2s . co m*/ * **************************************************- * ingrid-interface-csw * ================================================== * Copyright (C) 2014 - 2016 wemove digital solutions GmbH * ================================================== * Licensed under the EUPL, Version 1.1 or ? as soon they will be * approved by the European Commission - subsequent versions of the * EUPL (the "Licence"); * * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://ec.europa.eu/idabc/eupl5 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * **************************************************# */ import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 { private static ThreadLocal<Transformer> threadLocalTransformer = new ThreadLocal<Transformer>() { @Override public Transformer initialValue() { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); return transformer; } catch (TransformerConfigurationException e) { new RuntimeException("Error creating Transformer", e); } return null; } }; public static String nodeToString(Node node) { try { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); Transformer transformer = threadLocalTransformer.get(); transformer.reset(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { return e.getMessage(); } } }