Java XML Document to String getStringFromXMLDocument(Document doc)

Here you can find the source of getStringFromXMLDocument(Document doc)

Description

Serializes an XML document to a string

License

Open Source License

Parameter

Parameter Description
doc a parameter

Declaration

public static String getStringFromXMLDocument(Document doc) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//ww  w  . j a  v a  2  s .  com
     * Serializes an XML document to a string
     *
     * @param doc
     * @return
     */
    public static String getStringFromXMLDocument(Document doc) {
        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();
        return lsSerializer.writeToString(doc);
    }
}

Related

  1. getStringFromDoc(org.w3c.dom.Document doc)
  2. getStringFromDocument(Document doc)
  3. getStringFromDocument(Document doc)
  4. getStringFromDOM(Document doc)
  5. getStringFromDomDocument(org.w3c.dom.Document doc, org.w3c.dom.Document xslt)
  6. getStringFromXPath(Document doc, XPath xpath, String expression)
  7. getStringListFromXPath(Document doc, XPath xpath, String rootNodeExpression, String listExpression)
  8. getStringRepresentation(DocumentFragment df)
  9. getXml(Document doc)