Writing a DOM Document to an XML File : Writer « XML « Java

Writing a DOM Document to an XML File

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 main(String[] argv) throws Exception {
    Document doc = null;
    String filename = "name.xml";

    Source source = new DOMSource(doc);

    File file = new File(filename);
    Result result = new StreamResult(file);

    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);


Related examples in the same category

1.XML Document Writer
2.XML Writer
3.XMLWriter.java - serialize an XML document
4.Convenience methods for writing XML
5.Write DOM out
6.write Xml DOM Node
7.XMLWriter helper class
8.DOM writer
9.Write Xml (Node n, OutputStream os)
10.Makes writing XML much much easier
11.Use DOM L3 DOMBuilder, DOMBuilderFilter DOMWriter and other DOM L3 functionality to preparse, revalidate and safe document.