Returns a new Document instance. - Java XML

Java examples for XML:DOM Document

Description

Returns a new Document instance.

Demo Code


//package com.java2s;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class Main {
    /**/*from   w  w  w . j a v  a  2 s . c  o  m*/
     * Returns a new <tt>Document</tt> instance.
     * This method just does all the tedious business of mucking about
     * with factories for you.
     *
     * @return   an empty Document
     */
    public static Document newDocument() {
        try {
            return DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Unexpected error constructing "
                    + "default document factory", e);
        }
    }
}

Related Tutorials