Here you can find the source of writeXMLDocument(Document doc, String filename)
Parameter | Description |
---|---|
doc | the document |
filename | the path to the file in which to write the XML data writing operation fails |
public static void writeXMLDocument(Document doc, String filename)
//package com.java2s; // publish, distribute, sublicense, and/or sell copies of the Software, import java.util.logging.*; import java.io.File; import javax.xml.transform.OutputKeys; 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 { final static Logger log = Logger.getLogger("OpenDial"); /**/*from w ww . j av a 2 s. com*/ * Writes the XML document to the particular file specified as argument * * @param doc the document * @param filename the path to the file in which to write the XML data writing * operation fails */ public static void writeXMLDocument(Document doc, String filename) { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer; transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filename)); transformer.transform(source, result); log.fine("writing operation to " + filename + " successful!"); } catch (TransformerConfigurationException e) { log.warning(e.getMessage()); } catch (TransformerException e) { log.warning(e.getMessage()); } } }