Here you can find the source of printXML(Node node)
Parameter | Description |
---|---|
node | XML node |
public static String printXML(Node node)
//package com.java2s; //License from project: Apache License import java.io.StringWriter; 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 org.w3c.dom.Node; public class Main { /**/*from www. j a v a2s . co m*/ * Transforms an XML to a String * @param node XML node * @return String represenation of XML */ public static String printXML(Node node) { TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer serializer; try { serializer = tfactory.newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); StringWriter output = new StringWriter(); serializer.transform(new DOMSource(node), new StreamResult(output)); return output.toString(); } catch (TransformerException e) { throw new RuntimeException(e); } } }