Java XML DocumentBuilder Create getNewDocumentBuilder()

Here you can find the source of getNewDocumentBuilder()

Description

get New Document Builder

License

Apache License

Declaration

private static DocumentBuilder getNewDocumentBuilder() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static DocumentBuilder getNewDocumentBuilder() {
        try {//w  w w.  j  a  v a 2 s. co  m
            final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setAttribute("http://xml.org/sax/features/namespaces", true);
            factory.setAttribute("http://xml.org/sax/features/validation", false);
            factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
            factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            factory.setNamespaceAware(true);
            factory.setIgnoringElementContentWhitespace(true);
            factory.setValidating(false);
            factory.setIgnoringComments(false);
            final DocumentBuilder builder = factory.newDocumentBuilder();
            return builder;
        } catch (final ParserConfigurationException e) {
            throw new RuntimeException("Failed to create DocumentBuilder", e);
        }
    }
}

Related

  1. getDocumentBuilderFactory()
  2. getDocumentBuilderFactory(boolean isNamespaceAware)
  3. getDocumentBuilderFactory(String schema)
  4. getDocumentBuilderFactoryClassName()
  5. getNewDocumentBuilder()
  6. newDocumentBuilder()
  7. newDocumentBuilder()
  8. newDocumentBuilder()
  9. newDocumentBuilder()