Java XML Document to String document2String(Node document)

Here you can find the source of document2String(Node document)

Description

document String

License

Apache License

Declaration

static public String document2String(Node document) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;

public class Main {
    /**/*from   w w  w. java2  s  . c o  m*/
     *  XSL transform (identity) to create text from Document.
     */
    static private Transformer identityTransformer;

    static public String document2String(Node document) {
        if (document == null)
            return null;

        StringWriter stringWriter = new StringWriter();
        try {
            identityTransformer.transform(new DOMSource(document), new StreamResult(stringWriter));
        } catch (TransformerException e) {
            e.printStackTrace();
        }
        return stringWriter.toString();
    }
}

Related

  1. document2String(Document doc)
  2. document2String(Document doc, boolean prettyPrint)
  3. document2XmlString(Document xmldoc)
  4. documentToString(Document d)
  5. documentToString(Document d)
  6. documentToString(Document doc)