Java XML Node to String getStringFromDocument(Node doc)

Here you can find the source of getStringFromDocument(Node doc)

Description

get String From Document

License

BSD License

Declaration

public static String getStringFromDocument(Node doc) 

Method Source Code

//package com.java2s;
/*L//from w  w w.j  ava  2 s .com
 *  Copyright Ekagra Software Technologies Ltd.
 *  Copyright SAIC, SAIC-Frederick
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/cacore-sdk/LICENSE.txt for details.
 */

import java.io.*;

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 org.w3c.dom.Node;

public class Main {
    public static String getStringFromDocument(Node doc) {
        try {
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch (TransformerException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

  1. getNodeAsStream(Node node)
  2. getNodeSubtreeXMLString(final Node node)
  3. getNodeXml(Node node)
  4. getOuterXml(Node n)
  5. GetOuterXml(Node node)
  6. getStringFromNode(Node node)
  7. getStringFromNode(Node node)
  8. getStringFromXML(Node node)
  9. getText(final Node node)