Java XML Document Create createDocument(String namespaceURI, String qualifiedName)

Here you can find the source of createDocument(String namespaceURI, String qualifiedName)

Description

Creates a new document with the given namespace and document element.

License

Open Source License

Parameter

Parameter Description
namespaceURI The document namespace, may be <code>""</code>.
qualifiedName The document element name

Return

the created document

Declaration

public static Document createDocument(String namespaceURI, String qualifiedName) 

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 {
    /**/*from  w  w w  .  j  av  a2 s  .c  o m*/
     * Creates a new document with the given namespace and document element.
     * 
     * @param namespaceURI
     *            The document namespace, may be <code>""</code>.
     * @param qualifiedName
     *            The document element name
     * @return the created document
     */
    public static Document createDocument(String namespaceURI, String qualifiedName) {
        DOMImplementation impl = getDOMImplementation();
        return impl.createDocument(namespaceURI, qualifiedName, null);
    }

    /**
     * Returns a DOM implementation that has the following features:
     * <ul>
     * <li>Core 3.0</li>
     * <li>XML 3.0</li>
     * <li>LS</li>
     * </ul>
     * 
     * @return A {@link DOMImplementation} object that can be cast to
     *         {@link DOMImplementationLS}.
     */
    public static DOMImplementation getDOMImplementation() {
        try {
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            return registry.getDOMImplementation("Core 3.0 XML 3.0 LS");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. createDocument(String content, String charset)
  2. createDocument(String docElt)
  3. createDocument(String docElt)
  4. createDocument(String iName)
  5. createDocument(String mainType, String customType)
  6. createDocument(String pageID)
  7. createDocument(String root, NodeList content)
  8. createDocument(String rootElement)
  9. createDocument(String rootElementName)