Java XML Document Create newDocument()

Here you can find the source of newDocument()

Description

new Document

License

Open Source License

Return

A new document to populate

Declaration

public static Document newDocument() 

Method Source Code

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

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

public class Main {
    private static DocumentBuilderFactory mFactory = null;

    /**//from   w  w w.  j a  v  a2s.co  m
     * @return A new document to populate
     */
    public static Document newDocument() {
        ensureFactory();
        try {
            DocumentBuilder builder = mFactory.newDocumentBuilder();
            return builder.newDocument();
        } catch (ParserConfigurationException e) {
            return null;
        }
    }

    private static synchronized void ensureFactory() {
        if (mFactory == null) {
            mFactory = DocumentBuilderFactory.newInstance();
            //mFactory.setIgnoringComments(true);
            mFactory.setValidating(false);
            mFactory.setCoalescing(true);
            mFactory.setExpandEntityReferences(false);
        }
    }
}

Related

  1. newDocument()
  2. newDocument()
  3. newDocument()
  4. newDocument()
  5. newDocument()
  6. newDocument()
  7. newDocument()
  8. newDocument(boolean isNamespaceAware, boolean isValidating)
  9. newDocument(File file)