Android XML Document Save doc2XmlFile(Document doc, String filename)

Here you can find the source of doc2XmlFile(Document doc, String filename)

Description

doc Xml File

Declaration

public static boolean doc2XmlFile(Document doc, String filename) 

Method Source Code

//package com.java2s;
import java.io.File;

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 boolean doc2XmlFile(Document doc, String filename) {
        boolean flag = true;
        try {// www .  j a  v a2  s  . c  om
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result = new StreamResult(new File(filename));
            transformer.transform(source, result);
        } catch (Exception ex) {
            flag = false;
            ex.printStackTrace();
        }
        return flag;
    }
}

Related

  1. WriteXml(OutputStream stream, Document document)