Java XML Document to File writeXmlFile(Document doc, File file)

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

Description

write Xml File

License

Open Source License

Declaration

public static void writeXmlFile(Document doc, File file) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright (c) 2012 Google, Inc./*from w  w  w .j a va 2 s  .  c  o m*/
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors:
 *  Google, Inc. - initial API and implementation
 *******************************************************************************/

import java.io.File;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
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 writeXmlFile(Document doc, File file) throws Exception {
        // Prepare the DOM document for writing
        Source source = new DOMSource(doc);
        // Prepare the output file
        Result result = new StreamResult(file);
        // Write the DOM document to the file
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.transform(source, result);
    }
}

Related

  1. writeXML(Document doc, String fileName)
  2. writeXML(final File file, final Document doc)
  3. writeXML(String OUTPUT_XML_FILE, org.w3c.dom.Document xmlDoc)
  4. writeXMLDocument(Document doc, String filename)
  5. writeXMLDocumentToFile(Document doc, String outputFilename)
  6. writeXmlFile(Document doc, File file)
  7. writeXmlFile(Document doc, File file, boolean indent, String encoding)
  8. writeXmlFile(Document doc, String filename)
  9. writeXmlFile(Document doc, String filename)