Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * Create a new DocumentBuilder factory with validation disabled.
     * The parser returned is not specifically set-up for DAS, and can be
     * used in any case where you want a non-validating parser.
     *
     * @return a non-validating DocumentBuilderFactory
     */
    public static DocumentBuilderFactory nonValidatingFactory() {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        setFeature(factory, "http://xml.org/sax/features/validation");
        setFeature(factory, "http://apache.org/xml/features/validation/dynamic");
        setFeature(factory, "http://apache.org/xml/features/nonvalidating/load-external-dtd");
        return factory;
    }

    private static void setFeature(DocumentBuilderFactory factory, String feature) {
        try {
            factory.setFeature(feature, false);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
    }
}