Here you can find the source of writeXmlFile(Element doc, String filename)
Parameter | Description |
---|---|
doc | XML element |
filename | Filename of the file where to write XML |
public static void writeXmlFile(Element doc, String filename)
//package com.java2s; //License from project: Apache License 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.Element; public class Main { /**/*from www.ja va2s . c om*/ * Writes an XML element to a given file * @param doc XML element * @param filename Filename of the file where to write XML */ public static void writeXmlFile(Element doc, String filename) { try { Source source = new DOMSource(doc); File file = new File(filename); Result result = new StreamResult(file); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } catch (Exception e) { throw new RuntimeException(e); } } }