Java XML Document Create newXMLDocument()

Here you can find the source of newXMLDocument()

Description

new XML Document

License

Open Source License

Declaration

public static Document newXMLDocument() 

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;
import org.w3c.dom.Node;

public class Main {

    public static Document newXMLDocument() {
        try {/*from  www.  j  av a2s .c  o  m*/
            return newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    public static Document newXMLDocument(Node node) {
        Document doc = newXMLDocument();
        doc.appendChild(doc.importNode(node, true));
        return doc;
    }

    public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
        return newDocumentBuilderFactory().newDocumentBuilder();
    }

    public static DocumentBuilderFactory newDocumentBuilderFactory() {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        return dbf;
    }
}

Related

  1. newDocument(File file)
  2. newDocument(String namespaceURI, String qualifiedName)
  3. newDocument(String rootName)
  4. newXmlDocument()
  5. newXmlDocument()
  6. newXMLDocument()
  7. string2Document(final String xml)
  8. string2Document(String xml, String encode)
  9. stringToDocument(final String xml)