Java XML Document Create createDocument(final String rootName)

Here you can find the source of createDocument(final String rootName)

Description

Creates a new DOM.

License

Open Source License

Declaration

public static Document createDocument(final String rootName) 

Method Source Code

//package com.java2s;
/*/*w  w w.  ja  v  a 2s.  c  o m*/
 * #%L
 * VisBio application for visualization of multidimensional biological
 * image data.
 * %%
 * Copyright (C) 2002 - 2014 Board of Regents of the University of
 * Wisconsin-Madison.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-2.0.html>.
 * #L%
 */

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

public class Main {
    /** Document builder for creating DOMs. */
    protected static DocumentBuilder docBuilder;

    /** Creates a new DOM. */
    public static Document createDocument(final String rootName) {
        if (docBuilder == null) {
            try {
                docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            } catch (final ParserConfigurationException exc) {
                exc.printStackTrace();
                return null;
            }
        }
        final Document doc = docBuilder.newDocument();
        if (rootName != null)
            doc.appendChild(doc.createElement(rootName));
        return doc;
    }
}

Related

  1. createDocument(boolean validating, boolean namespaceAware)
  2. createDocument(byte[] data)
  3. createDocument(File file)
  4. createDocument(File file)
  5. createDocument(final File file)
  6. createDocument(InputSource is)
  7. createDocument(Node node)
  8. createDocument(Node sourceNode)
  9. CreateDocument(Path xml, Path xsd)