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 if something goes wrong

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;

    /**/*from  w w  w.  ja v a  2  s . c  om*/
     * Creates a new DOM document.
     * 
     * @param docElt
     *            name of the document element
     * @return a new DOM document if something goes wrong
     */
    public static Document createDocument(String docElt) {
        getImplementation();
        return impl.createDocument("", docElt, null);
    }

    public static Document createDocument(String namespaceURI, String docElt) {
        getImplementation();
        return impl.createDocument(namespaceURI, 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() {
        if (registry == null) {
            try {
                registry = DOMImplementationRegistry.newInstance();
            } catch (ClassCastException | ClassNotFoundException | InstantiationException
                    | IllegalAccessException e) {
                e.printStackTrace();
            }
        }

        if (impl == null) {
            impl = registry.getDOMImplementation("Core 3.0 XML 3.0 LS");
        }
    }
}

Related

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