Java XML Document Create createDocument(String docElt)

Here you can find the source of createDocument(String docElt)

Description

Creates a new DOM document.

License

Open Source License

Parameter

Parameter Description
docElt name of the document element

Return

a new DOM document

Declaration

public static Document createDocument(String docElt) 

Method Source Code

//package com.java2s;

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

import org.w3c.dom.bootstrap.DOMImplementationRegistry;

public class Main {
    private static DOMImplementation impl;
    private static DOMImplementationRegistry registry;

    /**//w w  w.j av  a 2  s.com
     * Creates a new DOM document.
     * 
     * @param docElt
     *            name of the document element
     * @return a new DOM document
     */
    public static Document createDocument(String docElt) {
        getImplementation();
        return impl.createDocument("", docElt, null);
    }

    /**
     * Creates a new instance of the DOM registry and get an implementation of DOM 3 with Load Save
     * objects.
     */
    private static void getImplementation() {
        try {
            if (registry == null) {
                registry = DOMImplementationRegistry.newInstance();
            }

            if (impl == null) {
                impl = registry.getDOMImplementation("Core 3.0 XML 3.0 LS");
                if (impl == null) {
                    throw new RuntimeException("no DOM 3 implementation found");
                }
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("DOM error", e);
        } catch (InstantiationException e) {
            throw new RuntimeException("DOM error", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("DOM error", e);
        }
    }
}

Related

  1. createDocument(Node node)
  2. createDocument(Node sourceNode)
  3. CreateDocument(Path xml, Path xsd)
  4. createDocument(String content, String charset)
  5. createDocument(String docElt)
  6. createDocument(String iName)
  7. createDocument(String mainType, String customType)
  8. createDocument(String namespaceURI, String qualifiedName)
  9. createDocument(String pageID)