Java XML DocumentBuilder Create getDocumentBuilder(boolean secure)

Here you can find the source of getDocumentBuilder(boolean secure)

Description

get Document Builder

License

Apache License

Declaration

public static DocumentBuilder getDocumentBuilder(boolean secure) throws ParserConfigurationException 

Method Source Code

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

import javax.xml.XMLConstants;

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

public class Main {
    public static DocumentBuilder getDocumentBuilder(boolean secure) throws ParserConfigurationException {
        String feature;// w w  w.j  a  v  a 2 s .  c  o m
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        feature = "http://xml.org/sax/features/external-general-entities";
        factory.setFeature(feature, false);
        feature = "http://xml.org/sax/features/external-parameter-entities";
        factory.setFeature(feature, false);
        feature = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
        factory.setFeature(feature, false);
        feature = "http://apache.org/xml/features/disallow-doctype-decl";
        factory.setFeature(feature, true);
        factory.setXIncludeAware(false);
        factory.setExpandEntityReferences(false);
        factory.setNamespaceAware(true);
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secure);
        return factory.newDocumentBuilder();
    }
}

Related

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