Java XML Node to String nodeToString(Node doc)

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

Description

node To String

License

Open Source License

Declaration

public static String nodeToString(Node doc) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.StringWriter;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
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 {
    public static String nodeToString(Node doc) {
        try {//from   w  ww .  ja  v  a 2  s  . c  om
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch (TransformerException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

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