Java XML DOM to String domNodeToString(Node node)

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

Description

dom Node To String

License

Apache License

Declaration

public static String domNodeToString(Node node) throws TransformerException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;

import javax.xml.transform.OutputKeys;
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 java.io.StringWriter;

public class Main {
    public static String domNodeToString(Node node) throws TransformerException {
        StringWriter writer = new StringWriter();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(writer));
        return writer.toString();
    }/*from  www  .ja v a2  s .c o  m*/
}

Related

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