Here you can find the source of asString(Node node)
Parameter | Description |
---|---|
node | never <code>null</code> |
Parameter | Description |
---|---|
Exception | an exception |
null
public static String asString(Node node) throws Exception
//package com.java2s; //License from project: Apache License import java.io.StringWriter; import javax.xml.transform.Transformer; 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 w w w.ja va 2s . c o m * Creates a {@link String} out of a {@link Node} * * @param node * never <code>null</code> * @return the node as string, never <code>null</code> * @throws Exception */ public static String asString(Node node) throws Exception { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } }