Being able to read XML information is all well and good, but for the language to be truly useful to us, our Java programs probably need to be able to write out XML information as well. The following program is a bare bones model of a program that both reads from and writes to the same XML file:
package writingxml; import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.*; import org.xml.sax.*; public class WritingXML { public static void main(String[] args) { File xmlFile = new File("cars.xml"); Document dom = LoadXMLDocument(xmlFile); WriteXMLDocument(dom, xmlFile); } private static void WriteXMLDocument
(Document doc, File destination) { try{ /...