Java XML Document to File writeDocument(Document document, File file)

Here you can find the source of writeDocument(Document document, File file)

Description

write Document

License

Open Source License

Declaration

public static void writeDocument(Document document, File file) throws TransformerException 

Method Source Code


//package com.java2s;
//it under the terms of the GNU Affero General public static License as published by

import java.io.File;

import java.io.OutputStream;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
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 writeDocument(Document document, File file) throws TransformerException {
        TransformerFactory transformFactory = TransformerFactory.newInstance();
        Transformer idTransform = transformFactory.newTransformer();
        Source input = new DOMSource(document);
        Result output = new StreamResult(file);
        idTransform.transform(input, output);
    }/*from ww w.  j a v a2 s .c  om*/

    public static void writeDocument(Document document, OutputStream out) throws TransformerException {
        TransformerFactory transformFactory = TransformerFactory.newInstance();
        Transformer idTransform = transformFactory.newTransformer();
        Source input = new DOMSource(document);
        Result output = new StreamResult(out);
        idTransform.transform(input, output);
    }
}

Related

  1. writeDocToFile(Document doc, String fileName)
  2. writeDocument(Document doc, String filename)
  3. writeDocument(Document doc, String filePath)
  4. writeDocument(Document doc, String filePath)
  5. writeDocument(Document document, File file)
  6. writeDocument(Document document, String path)
  7. writeDocumentTo(Document doc, File file)
  8. writeDocumentToFile(Document document, String filePathname, String method, int indent)
  9. writeDOM2XMLFile(Document domDoc, String fileName)