Code example for SAXSource

0
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        InputStream stream = ClassLoader.getSystemResourceAsStream(DOUBLE_ERROR_XML);
        Source source = new SAXSource(xr, new InputSource(stream));
        try { 
            unmarshaller.setSchema(this.schema);
            unmarshaller.unmarshal(source);
        } catch (UnmarshalException ex) {
            assertEquals(2, eventHandler.getErrorCount());
            return; 
        } 
        fail("No Exceptions thrown."); 
    } 
 
    public void testFailOnSecondErrorSAXSourceWithClass() throws Exception { 
        CustomErrorValidationEventHandler eventHandler = new CustomErrorValidationEventHandler();
        unmarshaller.setEventHandler(eventHandler);
        SAXParserFactory spf = SAXParserFactory.newInstance();
Experience pair programming with AI  Get Codota for Java