Example usage for javax.xml.parsers DocumentBuilder isValidating

List of usage examples for javax.xml.parsers DocumentBuilder isValidating

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder isValidating.

Prototype


public abstract boolean isValidating();

Source Link

Document

Indicates whether or not this parser is configured to validate XML documents.

Usage

From source file:XMLBody.java

/**
 * Load XML document and parse it into DOM.
 * //w  ww.j a  v a2 s . co  m
 * @param input
 * @throws ParsingException
 */
public void loadXML(InputStream input) throws Exception {
    try {
        // Create Document Builder Factory
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();

        docFactory.setValidating(false);
        // Create Document Builder
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        docBuilder.isValidating();

        // Disable loading of external Entityes
        docBuilder.setEntityResolver(new EntityResolver() {
            // Dummi resolver - alvays do nothing
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                return new InputSource(new StringReader(""));
            }

        });

        // open and parse XML-file
        xmlDocument = docBuilder.parse(input);

        // Get Root xmlElement
        rootElement = xmlDocument.getDocumentElement();
    } catch (Exception e) {
        throw new Exception("Error load XML ", e);
    }

}