Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    /**
     * Node to string.
     *
     * @param node
     *            the node
     * @return the string
     */
    public static String nodeToString(Node node) {
        Document doc = node.getOwnerDocument();
        DOMImplementationLS domImplLS = (DOMImplementationLS) doc.getImplementation();
        LSSerializer serializer = domImplLS.createLSSerializer();
        serializer.getDomConfig().setParameter("xml-declaration", false);
        String string = serializer.writeToString(node);
        return string.trim();
    }
}