Java XML Node to String getNodeXml(Node node)

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

Description

get Node Xml

License

Open Source License

Declaration

public static String getNodeXml(Node node) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source 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 getNodeXml(Node node) throws Exception {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer trans = transformerFactory.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        StringWriter sw = new StringWriter();
        trans.transform(new DOMSource(node), new StreamResult(sw));
        return sw.getBuffer().toString();
    }//from  w ww .  j  av a 2  s. co  m
}

Related

  1. getAttributeValue(Node node, String attrName)
  2. getDescriptionOfNode(Node node)
  3. getNodeAsInputStream(Node node)
  4. getNodeAsStream(Node node)
  5. getNodeSubtreeXMLString(final Node node)
  6. getOuterXml(Node n)
  7. GetOuterXml(Node node)
  8. getStringFromDocument(Node doc)
  9. getStringFromNode(Node node)