Java XML Node Transform copyTreeToResult(Node tree, Result result)

Here you can find the source of copyTreeToResult(Node tree, Result result)

Description

Copy DOM tree to a SOAP tree.

License

Open Source License

Parameter

Parameter Description
tree a parameter
node a parameter

Return

The parent of the new child node.

Declaration

public static boolean copyTreeToResult(Node tree, Result result) 

Method Source Code

//package com.java2s;

import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Node;

public class Main {
    /**//from   w  w  w. ja  v  a 2  s .c  om
     * Copy DOM tree to a SOAP tree.
     * @param tree
     * @param node
     * @return The parent of the new child node.
     */
    public static boolean copyTreeToResult(Node tree, Result result) {
        try {
            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            DOMSource source = new DOMSource(tree);
            transformer.transform(source, result);
            return true; // Success
        } catch (TransformerConfigurationException tce) {
            // Error generated by the parser
            tce.printStackTrace();
        } catch (TransformerException te) {
            // Error generated by the parser
            te.printStackTrace();
        }
        return false; // Failure
    }
}

Related

  1. buildXml(Node node)
  2. createInputStream(Node node)
  3. createXML(Node doc)
  4. getAsText(Node n)
  5. getHumanReadableXml(final Node node)