Java XML Document to File writeXmlFile(Document doc, String filename)

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

Description

write Xml File

License

Open Source License

Declaration

public static void writeXmlFile(Document doc, String filename)
            throws TransformerException 

Method Source Code

//package com.java2s;
import org.w3c.dom.Document;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;

public class Main {
    public static void writeXmlFile(Document doc, String filename)
            throws TransformerException {

        // Prepare the DOM document for writing
        Source source = new DOMSource(doc);

        // Prepare the output file
        File file = new File(filename);
        Result result = new StreamResult(file);

        // Write the DOM document to the file
        Transformer xformer = TransformerFactory.newInstance()
                .newTransformer();/*w w w  .  ja v a 2  s  . c  o  m*/
        xformer.transform(source, result);
    }
}

Related

  1. writeXMLDocument(Document doc, String filename)
  2. writeXMLDocumentToFile(Document doc, String outputFilename)
  3. writeXmlFile(Document doc, File file)
  4. writeXmlFile(Document doc, File file)
  5. writeXmlFile(Document doc, File file, boolean indent, String encoding)
  6. writeXmlFile(Document doc, String filename)
  7. writeXmlFile(Document doc, String filename)
  8. writeXMLFile(Document document, Writer writer)
  9. writeXmlFile(File file, Document document)