Java tutorial
//package com.java2s; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static Document createDocument() throws Exception { DocumentBuilderFactory localDocumentBuilderFactory = getDocumentBuilderFactoryInstance(); DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder(); return localDocumentBuilder.newDocument(); } public static Document createDocument(String paramString) throws Exception { DocumentBuilderFactory localDocumentBuilderFactory = getDocumentBuilderFactoryInstance(); DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder(); Document localDocument = localDocumentBuilder.newDocument(); Element localElement = localDocument.createElement(paramString); localDocument.appendChild(localElement); return localDocument; } private static DocumentBuilderFactory getDocumentBuilderFactoryInstance() { DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); localDocumentBuilderFactory.setNamespaceAware(true); return localDocumentBuilderFactory; } }