Java XML Document Create createNewDocument(DocumentBuilder docBuilder)

Here you can find the source of createNewDocument(DocumentBuilder docBuilder)

Description

Create a new XML Document.

License

Open Source License

Parameter

Parameter Description
docBuilder DocumentBuilder. Setting this to null will create a new DocumentBuilder.

Return

Document

Declaration

public static final Document createNewDocument(DocumentBuilder docBuilder) throws ParserConfigurationException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   w w  w .j  a v  a  2 s.  c o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

import org.w3c.dom.Document;

public class Main {
    /**
     * Create a new XML Document.
     * @param docBuilder DocumentBuilder. Setting this to null will create a new DocumentBuilder.
     * @return Document
     */
    public static final Document createNewDocument(DocumentBuilder docBuilder) throws ParserConfigurationException {
        if (docBuilder == null) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(false);
            factory.setValidating(false);
            docBuilder = factory.newDocumentBuilder();
        }
        Document doc = docBuilder.newDocument();
        return doc;
    }
}

Related

  1. createEmptyDocument()
  2. createEmptyDocument()
  3. createEmptyDocument(final DocumentBuilder builder)
  4. createEmptyElement(Document doc, QName qname)
  5. createNewDocument()
  6. createNewDocument(String namespaceURI, String qualifiedName)
  7. getDocument()
  8. getDocument()
  9. getDocument()