Java tutorial
//package com.java2s; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; public class Main { /** * Creates a new XML document. * @return the XML document */ public static Document createDocument() { try { DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); DocumentBuilder db = fact.newDocumentBuilder(); return db.newDocument(); } catch (ParserConfigurationException e) { //will probably never be thrown because we're not doing anything fancy with the configuration throw new RuntimeException(e); } } }