Programmazione:Java/Write DOM to XML

Da WikiSitech.
Versione del 22 gen 2008 alle 01:10 di Mazzotti (discussione | contributi) (Nuova pagina: == Writing a DOM Document to an XML File == <code java> // This method writes a DOM document to a file public static void writeXmlFile(Document doc, String filename) { try { ...)
(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)
Vai alla navigazioneVai alla ricerca

Writing a DOM Document to an XML File

// This method writes a DOM document to a file public static void writeXmlFile(Document doc, String filename) {

   try {
       // Prepare the DOM document for writing
       Source source = new DOMSource(doc);
   
       // Prepare the output file
       File file = new File(filename);
       Result result = new StreamResult(file);
   
       // Write the DOM document to the file
       Transformer xformer = TransformerFactory.newInstance().newTransformer();
       xformer.transform(source, result);
   } catch (TransformerConfigurationException e) {
   } catch (TransformerException e) {
   }

}