Java XML Document to String xmlDocumentToString(Document doc)

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

Description

xml Document To String

License

Open Source License

Declaration

public static String xmlDocumentToString(Document doc) 

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.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 {
    public static String xmlDocumentToString(Document doc) {
        try {//www  .j a  va 2  s. c  o  m
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch (TransformerException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

  1. xmlDocToString(Document doc)
  2. xmlDocToString(Document doc)
  3. xmlDocumentDecode(final String xmlURI)
  4. xmlDocumentToString(Document doc)
  5. xmlDocumentToString(Document doc)
  6. xmlDocumentToString(Document document)
  7. xmlDocumentToString(final Document document)
  8. xmlDocumentToString(Node d)
  9. xmlDOMDocumentToString(Document doc)