Here you can find the source of renderNode(Node node)
Parameter | Description |
---|---|
node | The xml node to render |
public static String renderNode(Node node)
//package com.java2s; //License from project: LGPL import org.w3c.dom.*; 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.*; public class Main { /**//from w ww . j ava 2 s . co m * Renders an XML node to a string * @param node The xml node to render * @return the rendered string or null if it failed conversion */ public static String renderNode(Node node) { if (node == null) return null; try { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (Throwable e) { return null; } } }