Example usage for org.w3c.dom.ls LSSerializer writeToString

List of usage examples for org.w3c.dom.ls LSSerializer writeToString

Introduction

In this page you can find the example usage for org.w3c.dom.ls LSSerializer writeToString.

Prototype

public String writeToString(Node nodeArg) throws DOMException, LSException;

Source Link

Document

Serialize the specified node as described above in the general description of the LSSerializer interface.

Usage

From source file:Main.java

public static String nodeToString(Node node) {
    DOMImplementationLS ls = (DOMImplementationLS) node.getOwnerDocument().getImplementation().getFeature("LS",
            "3.0");
    LSSerializer seri = ls.createLSSerializer();
    return seri.writeToString(node);
}

From source file:Main.java

public static void printXmlDocument(Document document) {
    DOMImplementationLS domImplementationLS = (DOMImplementationLS) document.getImplementation();
    LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
    String string = lsSerializer.writeToString(document);
    System.out.println(string);//from   www  . j  ava  2  s .co m
}

From source file:Main.java

public static String documentToString(Document doc) {
    DOMImplementationLS domImplLS = (DOMImplementationLS) doc.getImplementation();
    LSSerializer serializer = domImplLS.createLSSerializer();
    return serializer.writeToString(doc);
}

From source file:Main.java

public static String elementToString(Element el) {
    if (el == null)
        return "";
    Document document = el.getOwnerDocument();
    DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
    LSSerializer serializer = domImplLS.createLSSerializer();
    return serializer.writeToString(el);
}

From source file:Main.java

public static String toString(Document d) {
    DOMImplementationLS domImplementation = (DOMImplementationLS) d.getImplementation();
    LSSerializer lsSerializer = domImplementation.createLSSerializer();
    return lsSerializer.writeToString(d);
}

From source file:Main.java

public static String lsSerialize(Document doc) {
    DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
    LSSerializer lsSerializer = domImplementation.createLSSerializer();
    return lsSerializer.writeToString(doc);
}

From source file:Main.java

public static String serializeNode(Node node) throws LSException, IllegalAccessException, DOMException,
        InstantiationException, ClassNotFoundException, ClassCastException {
    System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl");
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();
    String serializedElement = writer.writeToString(node);
    return serializedElement;
}

From source file:Main.java

public static String lsSerializeDom(Node doc) throws Exception {
    if (doc == null)
        return null;
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");

    LSSerializer writer = impl.createLSSerializer();
    return writer.writeToString(doc);
}

From source file:Main.java

/**
 * Serialises the XML node into a string.
 * //  w w w  .  ja v  a2  s. c om
 * @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 "";
    }
}

From source file:Main.java

public static String serializeNode(Node node) throws LSException, IllegalAccessException, DOMException,
        InstantiationException, ClassNotFoundException, ClassCastException {
    String serializedElement = null;
    if (node != null) {
        DOMImplementationLS impl = getDOMImplementationLS(node);
        LSSerializer writer = impl.createLSSerializer();
        serializedElement = writer.writeToString(node);
    }//w  w w  .jav  a  2s .c  o m
    return serializedElement;
}