Java XML Document Serialize serialiseDOM(Document doc, String filepath)

Here you can find the source of serialiseDOM(Document doc, String filepath)

Description

serialise DOM

License

Open Source License

Declaration

public static void serialiseDOM(Document doc, String filepath) 

Method Source Code

//package com.java2s;
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

import java.io.File;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
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 {
    public static void serialiseDOM(Document doc, String filepath) {

        Transformer transformer;//w  ww .j  a  v  a 2 s.  c  o  m
        try {
            transformer = TransformerFactory.newInstance().newTransformer();
            Result output = new StreamResult(new File(filepath));
            Source input = new DOMSource(doc);
            transformer.transform(input, output);
        } catch (TransformerConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerFactoryConfigurationError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

Related

  1. serialise(Document doc, OutputStream out)
  2. serialize(Document d, File f)
  3. serialize(Document d, OutputStream out, URL transformerLocation, Map properties)
  4. serialize(Document doc)
  5. serialize(Document doc, Writer out)