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() 

Method Source Code

//package com.java2s;
// Released under the terms of the CPL Common Public License version 1.0.

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

public class Main {
    private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    private static ThreadLocal<DocumentBuilder> documentBuilder = new ThreadLocal<DocumentBuilder>();

    private static DocumentBuilder getDocumentBuilder() {
        DocumentBuilder builder = documentBuilder.get();
        if (builder == null) {
            try {
                builder = documentBuilderFactory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                throw new RuntimeException(e);
            }//  w ww  .  j ava  2s  .  c  om
            documentBuilder.set(builder);
        }
        return builder;
    }
}

Related

  1. getDocumentBuilder()
  2. getDocumentBuilder()
  3. getDocumentBuilder()
  4. getDocumentBuilder()
  5. getDocumentBuilder()
  6. getDocumentBuilder(boolean NamespaceAwareness)
  7. getDocumentBuilder(boolean secure)
  8. getDocumentBuilderFactory()
  9. getDocumentBuilderFactory()