Java XML Document to File writeXML(String OUTPUT_XML_FILE, org.w3c.dom.Document xmlDoc)

Here you can find the source of writeXML(String OUTPUT_XML_FILE, org.w3c.dom.Document xmlDoc)

Description

write XML

License

Open Source License

Declaration

public static void writeXML(String OUTPUT_XML_FILE,
            org.w3c.dom.Document xmlDoc) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 Dipanjan Das //ww  w . j a v a 2s .c o  m
 * Language Technologies Institute, 
 * Carnegie Mellon University, 
 * All Rights Reserved.
 * 
 * XmlUtils.java is part of SEMAFOR 2.0.
 * 
 * SEMAFOR 2.0 is free software: you can redistribute it and/or modify  it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * SEMAFOR 2.0 is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License along
 * with SEMAFOR 2.0.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.io.File;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

public class Main {
    public static void writeXML(String OUTPUT_XML_FILE,
            org.w3c.dom.Document xmlDoc) {
        try {
            javax.xml.transform.Source source = new DOMSource(xmlDoc);
            System.out.println("writing File: " + OUTPUT_XML_FILE);
            // Prepare the output file
            File file = new File(OUTPUT_XML_FILE);
            Result result = new StreamResult(file);
            // Write the DOM document to the file
            javax.xml.transform.Transformer xformer = javax.xml.transform.TransformerFactory
                    .newInstance().newTransformer();
            xformer.setOutputProperty(OutputKeys.INDENT, "yes");
            xformer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "2");
            xformer.transform(source, result);
        } catch (Exception e) {
            System.err.println("Exception in writing file:"
                    + OUTPUT_XML_FILE);
            e.printStackTrace();
        }
    }
}

Related

  1. writeXML(Document doc, File file)
  2. writeXml(Document doc, File output)
  3. writeXml(Document doc, File outputFile)
  4. writeXML(Document doc, String fileName)
  5. writeXML(final File file, final Document doc)
  6. writeXMLDocument(Document doc, String filename)
  7. writeXMLDocumentToFile(Document doc, String outputFilename)
  8. writeXmlFile(Document doc, File file)
  9. writeXmlFile(Document doc, File file)