Java XML Document Serialize serialize(Document d, File f)

Here you can find the source of serialize(Document d, File f)

Description

serialize

License

Open Source License

Declaration

public static void serialize(Document d, File f) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

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 TransformerFactory tf;

    public static void serialize(Document d, File f) {
        try {//from  w  w  w  .ja  va2  s  .co m
            doSerialize(d, f);
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void doSerialize(Document d, File f) throws TransformerException, IOException {
        Transformer t = tf.newTransformer();
        FileOutputStream fos = new FileOutputStream(f);
        StreamResult sr = new StreamResult(fos);
        t.transform(new DOMSource(d), sr);
        fos.close();
    }
}

Related

  1. serialise(Document doc, OutputStream out)
  2. serialiseDOM(Document doc, String filepath)
  3. serialize(Document d, OutputStream out, URL transformerLocation, Map properties)
  4. serialize(Document doc)
  5. serialize(Document doc, Writer out)
  6. serialize(Document document, boolean prettyPrint)