Java XML Node Transform renderNode(Node node)

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

Description

Renders an XML node to a string

License

LGPL

Parameter

Parameter Description
node The xml node to render

Return

the rendered string or null if it failed conversion

Declaration

public static String renderNode(Node node) 

Method Source Code


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

import org.w3c.dom.*;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import java.io.*;

public class Main {
    /**//from w ww  . j ava  2  s  .  co m
     * Renders an XML node to a string
     * @param node The xml node to render
     * @return the rendered string or null if it failed conversion
     */
    public static String renderNode(Node node) {
        if (node == null)
            return null;
        try {
            StringWriter writer = new StringWriter();
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.transform(new DOMSource(node), new StreamResult(writer));
            return writer.toString();
        } catch (Throwable e) {
            return null;
        }

    }
}

Related

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