Java XML Node to String toXML(Node node)

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

Description

Xml to string.

License

Open Source License

Parameter

Parameter Description
node the node

Return

the string

Declaration

public static String toXML(Node node) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.  jav a2 s .c om*/
    
Copyright (c) 2009-2011, AOL Inc.
All rights reserved.
    
This code is licensed under a BSD license.
    
*/

import java.io.StringWriter;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
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 {
    /**
     * Xml to string.
     * 
     * @param node
     *           the node
     * 
     * @return the string
     */
    public static String toXML(Node node) {
        try {
            Source source = new DOMSource(node);
            StringWriter stringWriter = new StringWriter();
            Result result = new StreamResult(stringWriter);
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.transform(source, result);
            return stringWriter.getBuffer().toString();
        } catch (Exception e) {
        }
        return null;
    }
}

Related

  1. toStringE(Node element)
  2. toText(Node node)
  3. toText(Node node)
  4. toWellKnowName(Node vertexStyleNode)
  5. toWriter(Node node, Writer writer, Map outputProperties)
  6. toXml(Node node)
  7. toXml(Node node)
  8. toXML(Node node)
  9. toXml(Node node, boolean keepHeader)