Java XML DocumentBuilder Create getDocumentBuilder()

Here you can find the source of getDocumentBuilder()

Description

get Document Builder

License

Open Source License

Declaration

private static DocumentBuilder getDocumentBuilder()
            throws ParserConfigurationException 

Method Source Code

//package com.java2s;
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
 * Copyright 2006-2008, 2011 Laszlo Systems, Inc.  All Rights Reserved.        *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/

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

public class Main {
    private static DocumentBuilderFactory documentBuilderFactory;
    private static DocumentBuilder documentBuilder;

    private static DocumentBuilder getDocumentBuilder()
            throws ParserConfigurationException {
        DocumentBuilder builder = documentBuilder;
        if (builder == null) {
            builder = getDocumentBuilderFactory().newDocumentBuilder();
            documentBuilder = builder;/*  w ww  .  ja v a 2  s .  c  o m*/
        } else {
            try {
                builder.reset();
            } catch (UnsupportedOperationException e) {
            }
        }
        return builder;
    }

    private static DocumentBuilderFactory getDocumentBuilderFactory() {
        DocumentBuilderFactory factory = documentBuilderFactory;
        if (factory == null) {
            factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(false);
            documentBuilderFactory = factory;
        }
        return factory;
    }
}

Related

  1. getDocumentBuilder()
  2. getDocumentBuilder()
  3. getDocumentBuilder()
  4. getDocumentBuilder()
  5. getDocumentBuilder()
  6. getDocumentBuilder()
  7. getDocumentBuilder()
  8. getDocumentBuilder()
  9. getDocumentBuilder()