Writing a DOM Document to an XML File


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.