Here you can find the source of getXmlString(Node n)
public static String getXmlString(Node n)
//package com.java2s; /*/* w w w.j av a 2s. c o m*/ * Copyright 2006-2007 Javector Software LLC * * Licensed under the GNU General Public License, Version 2 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/copyleft/gpl.html * * THE SOURCE CODE AND ACCOMPANYING FILES ARE PROVIDED WITHOUT ANY WARRANTY, * WRITTEN OR IMPLIED. * * The copyright holder provides this software under other licenses for those * wishing to include it with products or systems not licensed under the GPL. * Contact licenses@javector.com for more information. */ import org.w3c.dom.Node; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.StringWriter; public class Main { public static String getXmlString(Node n) { Transformer serializer = null; try { serializer = TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); StreamResult out = new StreamResult(sw); serializer.transform(new DOMSource(n), out); String result = ((StringWriter) out.getWriter()).getBuffer() .toString(); return result; } catch (TransformerException e) { return null; } } }