Java tutorial
//package com.java2s; /* * XMLUtils.java * * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium ERP system. * */ import org.w3c.dom.Document; import org.w3c.dom.Element; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; public class Main { public static Document makeEmptyXmlDocument() { return makeEmptyXmlDocument(null); } public static Document makeEmptyXmlDocument(String rootElementName) { Document document = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); // factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (Exception e) { //Debug.logError(e, module); } if (document == null) return null; if (rootElementName != null) { Element rootElement = document.createElement(rootElementName); document.appendChild(rootElement); } return document; } }