Android XML Document Save WriteXml(OutputStream stream, Document document)

Here you can find the source of WriteXml(OutputStream stream, Document document)

Description

Write Xml

Declaration

public static void WriteXml(OutputStream stream, Document document)
            throws TransformerException 

Method Source Code

//package com.java2s;

import java.io.OutputStream;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
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 void WriteXml(OutputStream stream, Document document)
            throws TransformerException {

        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        Properties outFormat = new Properties();
        outFormat.setProperty(OutputKeys.INDENT, "yes");
        outFormat.setProperty(OutputKeys.METHOD, "xml");
        outFormat.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        outFormat.setProperty(OutputKeys.VERSION, "1.0");
        outFormat.setProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperties(outFormat);

        DOMSource domSource = new DOMSource(document.getDocumentElement());
        StreamResult result = new StreamResult(stream);
        transformer.transform(domSource, result);

    }//from  w w  w  .ja  va  2 s . co m
}

Related

  1. doc2XmlFile(Document doc, String filename)