Code example for XMLReader

Methods: parsesetEntityResolversetErrorHandler

            xmlReader = parser.getXMLReader();
        } catch (Exception e) {
            throw new RuntimeException(e);
        xmlReader.setEntityResolver(new AppSchemaEntityResolver());
        // We principally care about the failures themselves, but it is also possible to install a 
        // ContentHandler to output annotated XML that identifies the precise location of failures. 
        // That can be done with a serializer that implements both ContentHandler and ErrorHandler. 
        // It should be installed here (and used for the error handler): 
        // parser.setContentHandler(contentHandler); 
        xmlReader.setErrorHandler(new AppSchemaValidatorErrorHandler());
        try { 
            xmlReader.parse(new InputSource(input));
        } catch (RuntimeException e) {
            // Avoid gratuitous exception chaining. 
            // Resolver failures pass through this block. 
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);