Java XML Document Parse parseXmlDocToString(Document xmlDoc)

Here you can find the source of parseXmlDocToString(Document xmlDoc)

Description

parse Xml Doc To String

License

Open Source License

Declaration

private static String parseXmlDocToString(Document xmlDoc)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;

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

public class Main {
    private static String parseXmlDocToString(Document xmlDoc)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        // Add formatting to the xml document in case we want to save to a file
        System.setProperty(DOMImplementationRegistry.PROPERTY,
                "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
        final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        final LSSerializer writer = impl.createLSSerializer();
        writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
        writer.getDomConfig().setParameter("xml-declaration", true); // Set this to true if the declaration is needed to be outputted

        return writer.writeToString(xmlDoc);
    }/*from   w w w .  j  a va 2s .co  m*/
}

Related

  1. parseInitMap(InputStream in, DocumentBuilder builder, Map> initMap)
  2. parseMultipleWorkouts(Document doc)
  3. parseResponse(InputSource is, DocumentBuilder documentBuilder)
  4. parseToDocument(InputStream is, boolean debugModeEnabled)
  5. parseXMLDoc(Element element, Document doc, Map oauthResponse)
  6. parseXmlDocument(InputStream is, boolean namespaceAware)
  7. parseXMLDocument(String xml)
  8. parseXmlDocument(String xml, boolean namespaceAware)
  9. parseXMLDocument(String xmlDoc)