Here you can find the source of nodeToString(Node n)
Parameter | Description |
---|---|
n | the node |
Parameter | Description |
---|---|
Exception | an exception |
public static String nodeToString(Node n) throws Exception
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt 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 www . ja v a2s . c o m*/ * Generates an xml string from a node (not pretty formatted) * * @param n the node * @return the xml string * @throws Exception */ public static String nodeToString(Node n) throws Exception { StringWriter sw = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("omit-xml-declaration", "yes");//$NON-NLS-1$//$NON-NLS-2$ transformer.setOutputProperty("indent", "yes");//$NON-NLS-1$//$NON-NLS-2$ transformer.transform(new DOMSource(n), new StreamResult(sw)); return sw.toString(); } }