Java XML Node to String getStringFromNode(Node node)

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

Description

get String From Node

License

RPL License

Declaration

public static String getStringFromNode(Node node) throws Exception 

Method Source Code

//package com.java2s;
/*/*  w  w w. jav  a  2  s.c om*/
 * Unless explicitly acquired and licensed from Licensor under another license, the contents of
 * this file are subject to the Reciprocal Public License ("RPL") Version 1.5, or subsequent
 * versions as allowed by the RPL, and You may not copy or use this file in either source code
 * or executable form, except in compliance with the terms and conditions of the RPL
 *
 * All software distributed under the RPL is provided strictly on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH
 * WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific language
 * governing rights and limitations under the RPL.
 *
 * http://opensource.org/licenses/RPL-1.5
 *
 * Copyright 2012-2015 Open Justice Broker Consortium
 */

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 getStringFromNode(Node node) throws Exception {

        StringWriter writer = new StringWriter();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(writer));
        String xml = writer.toString();

        return xml;
    }
}

Related

  1. getNodeXml(Node node)
  2. getOuterXml(Node n)
  3. GetOuterXml(Node node)
  4. getStringFromDocument(Node doc)
  5. getStringFromNode(Node node)
  6. getStringFromXML(Node node)
  7. getText(final Node node)
  8. getXml(Node node)
  9. getXmlAsString(Node node)