Java XML Element to String toString(Element node)

Here you can find the source of toString(Element node)

Description

to String

License

Apache License

Declaration

public static String toString(Element node) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache 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.Element;

public class Main {
    public static String toString(Element node) throws Exception {
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        StringWriter buffer = new StringWriter();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(buffer));
        return buffer.toString();
    }//from   w  w  w.j  ava 2 s .  c  om
}

Related

  1. getStringValues(Element from, String elementName)
  2. getXmlString(Element node)
  3. getXMLStringFromNode(Element node)
  4. toString(Element e)
  5. toString(Element element)
  6. toString(Element xml)
  7. toStringNoIndent(Element aElement)