Posted By

monkey103 on 11/06/08


Tagged

java io DOM xml


Versions (?)

Writing a DOM Document to an XML File


 / Published in: Java
 

URL: http://www.exampledepot.com/egs/javax.xml.transform/WriteDom.html

  1. e518. Writing a DOM Document to an XML File
  2.  
  3. // This method writes a DOM document to a file
  4. public static void writeXmlFile(Document doc, String filename) {
  5. try {
  6. // Prepare the DOM document for writing
  7. Source source = new DOMSource(doc);
  8.  
  9. // Prepare the output file
  10. File file = new File(filename);
  11. Result result = new StreamResult(file);
  12.  
  13. // Write the DOM document to the file
  14. Transformer xformer = TransformerFactory.newInstance().newTransformer();
  15. xformer.transform(source, result);
  16. } catch (TransformerConfigurationException e) {
  17. } catch (TransformerException e) {
  18. }
  19. }

Report this snippet  

You need to login to post a comment.