get XML Document from DocumentBuilder - Java XML

Java examples for XML:DOM Document

Description

get XML Document from DocumentBuilder

Demo Code


//package com.java2s;
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 Document document;

    public static Document getDocument()
            throws ParserConfigurationException {
        if (document == null) {
            DocumentBuilderFactory docFactory = DocumentBuilderFactory
                    .newInstance();//from  w  w w .ja v a 2  s  .c o m
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
            document = docBuilder.newDocument();
        }
        return document;
    }
}

Related Tutorials