Java XML DOM to String domToString(Node node)

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

Description

dom To String

License

Open Source License

Declaration

static String domToString(Node node) 

Method Source Code


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

import java.io.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;

public class Main {
    static String domToString(Node node) {
        try {//from w ww  . j a  v a  2 s. c om
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            StringWriter writer = new StringWriter();
            transformer.transform(new DOMSource(node), new StreamResult(writer));
            return writer.toString();
        } catch (TransformerException te) {
            return "(TransformerException)";
        }
    }
}

Related

  1. domNodeListToString(NodeList nodeList)
  2. domNodeToString(Node node)
  3. domToString(Node domNode)
  4. domToString(Node domNode)
  5. domToString(Node domNode, boolean indent)
  6. domToString(Node node, int estSize)