Java XML Node to String nodeToString(Node n)

Here you can find the source of nodeToString(Node n)

Description

Generates an xml string from a node (not pretty formatted)

License

Open Source License

Parameter

Parameter Description
n the node

Exception

Parameter Description
Exception an exception

Return

the xml string

Declaration

public static String nodeToString(Node n) throws Exception 

Method Source Code

//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();
    }
}

Related

  1. nodeToString(final Node node)
  2. nodeToString(final Node node)
  3. nodeToString(final Node node)
  4. nodeToString(final Node node)
  5. nodeToString(Node doc)
  6. nodeToString(Node n)
  7. nodeToString(Node n)
  8. nodeToString(Node node)
  9. nodeToString(Node node)