Here you can find the source of writeXmlFile(Document doc, String filename)
Parameter | Description |
---|---|
doc | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
TransformerFactoryConfigurationError | an exception |
TransformerException | an exception |
public static void writeXmlFile(Document doc, String filename) throws TransformerFactoryConfigurationError, TransformerException
//package com.java2s; /*//from ww w . j a v a 2 s .c o m * Author(s): Pascal Heus (pheus@opendatafoundation.org) * * This product has been developed with the financial and * technical support of the UK Data Archive Data Exchange Tools * project (http://www.data-archive.ac.uk/dext/) and the * Open Data Foundation (http://www.opendatafoundation.org) * * Copyright 2007 University of Essex (http://www.esds.ac.uk) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA * The full text of the license is also available on the Internet at * http://www.gnu.org/copyleft/lesser.html * */ import java.io.File; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { /** * Writes and org.w3c.dom.Document to a file * * @param doc * @param filename * @throws TransformerFactoryConfigurationError * @throws TransformerException */ public static void writeXmlFile(Document doc, String filename) throws TransformerFactoryConfigurationError, TransformerException { // 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); } }