Here you can find the source of writeDomToFile(Document dom, File outFile)
Parameter | Description |
---|---|
dom | a parameter |
outFile | a parameter |
public static void writeDomToFile(Document dom, File outFile)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; 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 { /**/*from w ww . j ava 2 s. co m*/ * @param dom * @param outFile */ public static void writeDomToFile(Document dom, File outFile) { try { TransformerFactory transFact = TransformerFactory.newInstance(); Transformer transformer = transFact.newTransformer(); DOMSource source = new DOMSource(dom); StreamResult result; result = new StreamResult( new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding"))); transformer.transform(source, result); } catch (Exception e) { throw new RuntimeException( "Could not write dom tree '" + dom.getBaseURI() + "' to file '" + outFile.getName() + "'!", e); } } }