Here you can find the source of writeDomToFile(String filename, Document document)
Parameter | Description |
---|---|
filename | a parameter |
document | a parameter |
public static void writeDomToFile(String filename, Document document)
//package com.java2s; //License from project: Open Source License 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.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { /**/*www . j a va 2s . co m*/ * This method writes a DOM document to a file * * @param filename * @param document */ public static void writeDomToFile(String filename, Document document) { try { // Prepare the DOM document for writing Source source = new DOMSource(document); // Prepare the output file File file = new File(filename); Result result = new StreamResult(file); // Write the DOM document to the file // Get Transformer Transformer xformer = TransformerFactory.newInstance().newTransformer(); // Write to a file xformer.transform(source, result); } catch (TransformerConfigurationException e) { System.out.println("TransformerConfigurationException: " + e); } catch (TransformerException e) { System.out.println("TransformerException: " + e); } } }