Java XML DocumentBuilder Create newDocumentBuilder()

Here you can find the source of newDocumentBuilder()

Description

Creates a new DocumentBuilder object.

License

Apache License

Declaration

private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException 

Method Source Code

//package com.java2s;
/*/*from  w w w  .  ja v  a2  s. c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

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

public class Main {
    /**
     * Creates a new {@link DocumentBuilder} object.
     */
    private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        factory.setIgnoringComments(true);
        factory.setExpandEntityReferences(false);
        factory.setCoalescing(false);

        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

        return factory.newDocumentBuilder();
    }
}

Related

  1. newDocumentBuilder()
  2. newDocumentBuilder()
  3. newDocumentBuilder()
  4. newDocumentBuilder()
  5. newDocumentBuilder()
  6. newDocumentBuilder()
  7. newDocumentBuilder(Boolean disallowDoctypeDecl)
  8. newDocumentBuilder(boolean ignoreWhitespace, boolean ignoreComment)
  9. newDocumentBuilder(boolean nsAware, boolean validating)