Android XML Document Factory Create getDocumentBuilder()

Here you can find the source of getDocumentBuilder()

Description

DocumentBuilder instance

Declaration

private static DocumentBuilder getDocumentBuilder() 

Method Source Code

//package com.java2s;

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

public class Main {
    /**// www. j  a va  2  s .  c o m
     * singleton
     */
    private static DocumentBuilderFactory documentBuilderFactory = null;

    /**
     * DocumentBuilder instance
     * 
     * @return
     */
    private static DocumentBuilder getDocumentBuilder() {
        try {
            return getDocumentBuilderFactory().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            return null;
        }
    }

    /**
     * DocumentBuilderFactory instance (lazy initialization)
     * 
     * @return
     */
    private static DocumentBuilderFactory getDocumentBuilderFactory() {
        if (documentBuilderFactory == null) {
            documentBuilderFactory = DocumentBuilderFactory.newInstance();
        }
        return documentBuilderFactory;
    }
}

Related

  1. getDocumentBuilderFactory()
  2. getDocumentBuilderFactory()
  3. getDocumentBuilderFactory()
  4. CreateDocumentBuilderFactory()
  5. getDocumentBuilder()