Android XML Document to String Convert xmlToString(Document doc)

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

Description

xml To String

Declaration

public static String xmlToString(Document doc) 

Method Source Code

//package com.java2s;

import java.io.StringWriter;

import javax.xml.transform.Transformer;
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 xmlToString(Document doc) {
        final StringWriter sw = new StringWriter();

        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();// w ww.ja  va 2  s.c om

        try {
            Transformer transformer = transformerFactory.newTransformer();
            transformer.transform(new DOMSource(doc), new StreamResult(sw));

            return sw.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getXml(Document doc)
  2. numResults(Document doc)
  3. documentToString(Node n)
  4. getErrorText(Document xml)
  5. xmlDocumentToString(Document document)