Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; public class Main { public static Document getNewDocument() throws ParserConfigurationException { return getNewDocument(false); } public static Document getNewDocument(Boolean nameSpaceAwareness) throws ParserConfigurationException { DocumentBuilder builder = getDocumentBuilder(false); return builder.newDocument(); } private static DocumentBuilder getDocumentBuilder(boolean NamespaceAwareness) throws ParserConfigurationException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(NamespaceAwareness); //domFactory.setValidating(true); //domFactory.setIgnoringElementContentWhitespace( true ); domFactory.setAttribute("http://apache.org/xml/features/dom/include-ignorable-whitespace", Boolean.FALSE); return domFactory.newDocumentBuilder(); } }