Java tutorial
//package com.java2s; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static Document CreateCustomerFile(JFrame mainFrame) { Document CustomerDoc = null; try { DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance(); DocumentBuilder Build = Factory.newDocumentBuilder(); CustomerDoc = Build.newDocument(); Element rootElem = CustomerDoc.createElement("Customers"); CustomerDoc.appendChild(rootElem); } catch (ParserConfigurationException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(mainFrame, "There Was an Error Saving The File. Please Restart the Application."); System.exit(1); } return CustomerDoc; } }