Java XML Document Save to File saveDocument(Document doc, File file)

Here you can find the source of saveDocument(Document doc, File file)

Description

save Document

License

Open Source License

Declaration

public static void saveDocument(Document doc, File file)
        throws TransformerConfigurationException, TransformerException 

Method Source Code


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

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
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 saveDocument(Document doc, String xmlPath)
            throws TransformerConfigurationException, TransformerException {
        saveDocument(doc, new File(xmlPath));
    }//from   ww  w.  j  a va  2s .  c o  m

    public static void saveDocument(Document doc, File file)
            throws TransformerConfigurationException, TransformerException {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(file);
        transformer.transform(source, result);
    }
}

Related

  1. saveDoc(Document doc, OutputStream output)
  2. saveDoc(Document doc, String fileName)
  3. saveDocAsXML(Document doc, String filename)
  4. saveDocument(Document doc, File f)
  5. saveDocument(Document doc, File file)
  6. saveDocument(Document doc, String fullFileName)
  7. saveDocument(Document doc, Writer w)
  8. saveDocument(Document document, File outputFile)
  9. saveDocument(final Document doc, String encoding, String docPath)