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 TransformerConfigurationException, TransformerException 

Method Source Code

//package com.java2s;
/**/*  w  w w  .j a v  a  2  s . co m*/
 * *****************************************************************************
 *
 * Copyright (c) 2004-2011 Oracle Corporation.
 *
 * 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:
 *
 * Winston Prakash
 *
 ******************************************************************************
 */

import java.io.File;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
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 writeXmlFile(Document doc, File file)
            throws TransformerConfigurationException, TransformerException {
        Source source = new DOMSource(doc);
        Result result = new StreamResult(file);

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);
    }
}

Related

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