Android XML Document Create createXml(Document document)

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

Description

Creates XML from W3C Document from the xml.

License

LGPL

Parameter

Parameter Description
document the xml that needs to be converted.

Exception

Parameter Description
Exception is there is some error during operation.

Return

the XML.

Declaration

public static String createXml(Document document) throws Exception 

Method Source Code

//package com.java2s;
/*//from  w w  w .ja  v  a 2  s.c o m
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import java.io.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;

public class Main {
    /**
     * Creates XML from W3C Document from the xml.
     *
     * @param document the xml that needs to be converted.
     * @return the XML.
     * @throws Exception is there is some error during operation.
     */
    public static String createXml(Document document) throws Exception {
        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        StringWriter stringWriter = new StringWriter();
        StreamResult result = new StreamResult(stringWriter);
        DOMSource source = new DOMSource(document);
        transformer.transform(source, result);
        return stringWriter.toString();
    }
}

Related

  1. createDocument()
  2. newDocument(String rootName)
  3. stringToDocument(String xmlString)
  4. stringToDocument(String xmlString)
  5. createDocument(final String source, boolean isNamespaceAware)
  6. getOrCreateElement(Document doc, Element manifestElement, String elementName)
  7. getDomElement(File xmlFile)
  8. getDomElement(String aXml)
  9. LoadXml(String xml)