Java XML Document Create newDocument()

Here you can find the source of newDocument()

Description

Construct a new empty document.

License

Apache License

Declaration

public static Document newDocument() 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class Main {
    /** Construct a new empty document. */
    public static Document newDocument() {
        try {/*ww w .j a  v a2  s .  c o m*/
            return newBuilder().newDocument();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Cannot create new document", e);
        }
    }

    private static DocumentBuilder newBuilder() throws ParserConfigurationException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setExpandEntityReferences(false);
        factory.setIgnoringComments(true);
        factory.setCoalescing(true);
        return factory.newDocumentBuilder();
    }
}

Related

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