Java tutorial
//package com.java2s; //License from project: GNU General Public License import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; public class Main { public static Document newDocument() throws ParserConfigurationException { return newDocumentBuilder().newDocument(); } private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { // SAXParsers are not concurrency compatible, so always return a new instance to prevent thread issues DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); return dbf.newDocumentBuilder(); } }