Java XML Document Serialize serializeXMLToFile(Document document, File output)

Here you can find the source of serializeXMLToFile(Document document, File output)

Description

Serializes an XML document to disk

License

Open Source License

Declaration

public static void serializeXMLToFile(Document document, File output) 

Method Source Code

//package com.java2s;

import java.io.File;

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 {
    /**/*from ww w .j  a v a 2s.  co  m*/
     * Serializes an XML document to disk
     *
     */
    public static void serializeXMLToFile(Document document, File output) {

        try {

            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource domSource = new DOMSource(document);
            StreamResult result = new StreamResult(output);
            transformer.transform(domSource, result);

        } catch (TransformerConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Related

  1. serializeToByteArray(Document doc)
  2. serializeToString(org.w3c.dom.Document doc)
  3. serializeToStringLS(Document doc, Node node, String encoding)
  4. serializeXML(Document doc, Writer writer, boolean addXmlDeclaration)
  5. serializeXmlObject(org.w3c.dom.Document docToSerialize)