Java XML Document to File writeXml(Document doc, File outputFile)

Here you can find the source of writeXml(Document doc, File outputFile)

Description

write Xml

License

Open Source License

Declaration

public static void writeXml(Document doc, File outputFile) 

Method Source Code

//package com.java2s;
/**/*w  w w. jav  a  2  s  .  c  o m*/
 * Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved.
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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 writeXml(Document doc, File outputFile) {
        try {
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            Result output = new StreamResult(outputFile);
            Source input = new DOMSource(doc);
            transformer.transform(input, output);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

Related

  1. writeToFile(Document doc, String file)
  2. writeToFile(Document doc, String filePath)
  3. writeToFile(File file, Document doc)
  4. writeXML(Document doc, File file)
  5. writeXml(Document doc, File output)
  6. writeXML(Document doc, String fileName)
  7. writeXML(final File file, final Document doc)
  8. writeXML(String OUTPUT_XML_FILE, org.w3c.dom.Document xmlDoc)
  9. writeXMLDocument(Document doc, String filename)