Java XML Document Parse parseDocumentIntoStringXML(Document document)

Here you can find the source of parseDocumentIntoStringXML(Document document)

Description

Converts a Document into String representation UTF-8 conversion

License

Open Source License

Parameter

Parameter Description
document Document object to be parsed

Return

String representation of xml content

Declaration

public static String parseDocumentIntoStringXML(Document document)
        throws TransformerConfigurationException, TransformerException 

Method Source Code

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

import java.io.StringWriter;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

public class Main {
    /**/*from   w w  w .j a va  2s .c o  m*/
     * Converts a Document into String representation
     * UTF-8 conversion
     * @param   document    Document object to be parsed
     * @return  String representation of xml content
     */
    public static String parseDocumentIntoStringXML(Document document)
            throws TransformerConfigurationException, TransformerException {
        StringWriter output = new StringWriter();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(new DOMSource(document), new StreamResult(output));
        String newObjectResourceXML = output.toString();
        return newObjectResourceXML;
    }
}

Related

  1. parseDocument(String docText)
  2. parseDocument(String documentString)
  3. parseDocument(String documentString)
  4. parseDocument(String path)
  5. parseDocument(String xmlString)
  6. parseDocumentr(File f)
  7. parseFileToDocument(File f)
  8. parseHTMLDocument(String paramString)
  9. parseInitMap(InputStream in, DocumentBuilder builder, Map> initMap)