Here you can find the source of getXml(Node node)
Parameter | Description |
---|---|
node | Node to return the XML for. |
public static String getXml(Node node)
//package com.java2s; import org.w3c.dom.Node; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.StringWriter; public class Main { /**//from w w w . j av a 2s .co m * Returns a string that represents the given node. * * @param node Node to return the XML for. * @return Returns an XML string. */ public static String getXml(Node node) { try { Transformer tf = TransformerFactory.newInstance() .newTransformer(); tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); StreamResult dest = new StreamResult(new StringWriter()); tf.transform(new DOMSource(node), dest); return dest.getWriter().toString(); } catch (Exception e) { // ignore } return ""; } }