Java XML Node Serialize serialise(Node node)

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

Description

Serialises the XML node into a string.

License

Open Source License

Parameter

Parameter Description
node the XML node

Return

the corresponding string

Declaration

public static String serialise(Node node) 

Method Source Code


//package com.java2s;
// publish, distribute, sublicense, and/or sell copies of the Software, 

import java.util.logging.*;

import org.w3c.dom.Node;

import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    final static Logger log = Logger.getLogger("OpenDial");

    /**/*w w  w. ja v a2 s . co m*/
     * Serialises the XML node into a string.
     * 
     * @param node the XML node
     * @return the corresponding string
     */
    public static String serialise(Node node) {
        try {
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementationLS lsImpl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            LSSerializer serializer = lsImpl.createLSSerializer();
            return serializer.writeToString(node);
        } catch (Exception e) {
            log.fine("could not serialise XML node: " + e);
            return "";
        }
    }
}

Related

  1. getSerializer(final File file)
  2. serialiseBytes(Node n)
  3. serialize(Element e, boolean omitXMLDeclaration)
  4. serialize(Node doc)
  5. serialize(Node n, StreamResult sr)