Java XML Document Save to File saveDoc(Document doc, String fileName)

Here you can find the source of saveDoc(Document doc, String fileName)

Description

save Doc

License

Apache License

Declaration

public static void saveDoc(Document doc, String fileName) 

Method Source Code

//package com.java2s;
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions//from  w ww  .j a  v a 2s  .  c o  m
*
* Licensed 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.Transformer;
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 saveDoc(Document doc, String fileName) {
        try {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);

            StreamResult result = new StreamResult(new File(fileName));
            transformer.transform(source, result);
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. save(Document document, String fileName)
  2. save(Document document, String path)
  3. save(final String path, final Document xml)
  4. save(String filename, Document document)
  5. saveDoc(Document doc, OutputStream output)
  6. saveDocAsXML(Document doc, String filename)
  7. saveDocument(Document doc, File f)
  8. saveDocument(Document doc, File file)
  9. saveDocument(Document doc, File file)