Return to Snippet

Revision: 9450
at November 6, 2008 13:13 by monkey103


Initial Code
e518. Writing a DOM Document to an XML File

    // This method writes a DOM document to a file
    public static void writeXmlFile(Document doc, String filename) {
        try {
            // 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();
            xformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
        } catch (TransformerException e) {
        }
    }

Initial URL
http://www.exampledepot.com/egs/javax.xml.transform/WriteDom.html

Initial Description

                                

Initial Title
Writing a DOM Document to an XML File

Initial Tags
java, DOM, xml

Initial Language
Java