Java XML Document Create createDocument()

Here you can find the source of createDocument()

Description

Creates a new Document .

License

Open Source License

Return

Returns said .

Declaration

public static Document createDocument() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.*;

public class Main {
    private static DocumentBuilder m_builder;

    /**// w ww  .  ja  v  a 2 s .c  o m
     * Creates a new {@link Document}.
     *
     * @return Returns said {@link Document}.
     */
    public static Document createDocument() {
        return m_builder.newDocument();
    }

    /**
     * Creates a new {@link Document}.
     *
     * @param rootElementName The name of the root element.
     * @return Returns said {@link Document}.
     */
    public static Document createDocument(String rootElementName) {
        return createDocument(rootElementName, null);
    }

    /**
     * Creates a new {@link Document}.
     *
     * @param rootElementName The name of the root element.
     * @param xmlns The namespace of the document.
     * @return Returns said {@link Document}.
     */
    public static Document createDocument(String rootElementName, String xmlns) {
        final Document doc = createDocument();
        final Element root = doc.createElement(rootElementName);
        if (xmlns != null)
            root.setAttribute("xmlns", xmlns);
        doc.appendChild(root);
        return doc;
    }
}

Related

  1. createDocument()
  2. createDocument()
  3. createDocument()
  4. createDocument()
  5. createDocument()
  6. createDocument()
  7. createDocument()
  8. createDocument()
  9. createDocument()