Java XML Node Transform render(final Node node)

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

Description

render

License

Apache License

Declaration

public static String render(final Node node) 

Method Source Code

//package com.java2s;
//License from project: Apache 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 render(final Node node) {
        try {// w w  w . j  av  a 2 s .com
            final StringWriter writer = new StringWriter();
            final DOMSource domSource = new DOMSource(node);
            final StreamResult streamResult = new StreamResult(writer);
            final TransformerFactory tf = TransformerFactory.newInstance();
            final Transformer serializer = tf.newTransformer();
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.transform(domSource, streamResult);
            return writer.toString();
        } catch (final Exception e) {
            throw new RuntimeException("Error serializing DOM", e);
        }
    }
}

Related

  1. getHumanReadableXml(final Node node)
  2. getNodeValue(NodeList nodeList)
  3. getValueOfValueNode(Node n, boolean unescape)
  4. getXML(NodeList childNodes)
  5. nodeToByteArray(Node node)
  6. renderNode(final Node node, final boolean stripHeader)
  7. renderNode(Node node)
  8. save(Node node, OutputStream out)
  9. write(final Node node, final Result result)