Java XML Node to String toString(Node node)

Here you can find the source of toString(Node node)

Description

to String

License

Open Source License

Declaration

public static String toString(Node node) throws Exception 

Method Source Code

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

import java.io.StringWriter;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
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 {
    public static String toString(Node node) throws Exception {
        StringWriter w = new StringWriter();
        Source s = new DOMSource(node);
        Result r = new StreamResult(w);
        Transformer t = TransformerFactory.newInstance().newTransformer();
        // t.setOutputProperty("omit-xml-declaration", "yes");
        t.setOutputProperty("indent", "yes");
        t.transform(s, r);/*from  w  w w  .  j  av a 2 s .com*/
        return w.getBuffer().toString();
    }
}

Related

  1. toString(Node node)
  2. toString(Node node)
  3. toString(Node node)
  4. toString(Node node)
  5. toString(Node node)
  6. toString(Node node)
  7. toString(Node node)
  8. toString(Node node)
  9. toString(Node node, boolean formatted)