How to Create a Blank DOM Document | Java DOM Tutorial complete guide to DOM

This tutorial shows you how to create blank DOM document.
JAXP is a Java interface that provides Parsing XML documents.
The class DocumentBuilderFactory is responsible for creating new DOM parsers. Normally it is used to a DOM parser.
Creating an Empty DOM Document

public static Document createDomDocument() {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.newDocument();
        return doc;
    } catch (ParserConfigurationException e) {
    return null;
DocumentBuilder builder = Factory.newDocumentBuilder():- This method creates a DocumentBuilder object with the help of a DocumentBuilderFactory
Document doc = builder.newDocument():- This method obtain a new instance of a DOM Document object to build a DOM tree.

No comments:

Post a Comment

Please Provide your feedback here