Java XML Node to String nodeToString(final Node node)

Here you can find the source of nodeToString(final Node node)

Description

node To String

License

Open Source License

Declaration

public static String nodeToString(final Node node) 

Method Source Code

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

import java.io.StringWriter;

import javax.xml.transform.OutputKeys;
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 nodeToString(final Node node) {
        final TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer;//  w  ww .  j ava2 s .c  o  m
        try {
            transformer = transFactory.newTransformer();
            final StringWriter buffer = new StringWriter();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.transform(new DOMSource(node), new StreamResult(buffer));
            buffer.append("\n");
            return buffer.toString();
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getXMLString(Node node, boolean omitXmlDeclaration)
  2. getXMLStringFragmentFromNode(Node node)
  3. nodeToStr(final Node node)
  4. nodeToString(final Node node)
  5. nodeToString(final Node node)
  6. nodeToString(final Node node)
  7. nodeToString(Node doc)
  8. nodeToString(Node n)
  9. nodeToString(Node n)