Code example for Validator

Methods: setErrorHandler

0
        InputStream xsdStream = SdkRepository.getXsdStream();
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        Validator validator = schema.newValidator();
        if (handler != null) {
            validator.setErrorHandler(handler);
        } 
 
        return validator;
    } 
 
    /** Validate a valid sample using an InputStream */ 
    public void testValidateLocalRepositoryFile() throws Exception { 
 
        InputStream xmlStream =
            TestSdkRepository.class.getResourceAsStream("repository_sample.xml");
        Source source = new StreamSource(xmlStream);
 
        CaptureErrorHandler handler = new CaptureErrorHandler();
        Validator validator = getValidator(handler);
        validator.validate(source);