phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
115 stars 36 forks source link

Missing error report when validating #30

Closed jkiddo closed 8 years ago

jkiddo commented 8 years ago

There seems to be a bug when validating the schematron files. The following code reproduces the bug:

@Test
public void testOfSchematronPH() throws Exception {

    final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("ph-test.sch");
    final IPSErrorHandler aErrorHandler =new IPSErrorHandler() {

        @Override
        public void warn(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage) {
            // TODO Auto-generated method stub
            System.out.println(sMessage);
        }

        @Override
        public void error(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage, final Throwable t) {
            // TODO Auto-generated method stub
            System.out.println(sMessage);
        }

        @Override
        public void error(final IPSElement aSourceElement, final String sMessage) {
            // TODO Auto-generated method stub
            System.out.println(sMessage);
        }
    };

    aResPure.validateCompletely(aErrorHandler);
    Assert.assertTrue(aResPure.isValidSchematron());
}

Attached are the schematron files with an empty rule which is intentionally a bug. When running validateCompletely, none of the methods are hit in the IPSErrorHandler. However, when running isValidSchematron(), the schemas are deemed invalid

Archive.zip

phax commented 8 years ago

The first problem is the missing support for the XML Entity Handler when just reading from a file. I added support for this in the current HEAD revision.

The second things was, that the errorHandler must be assigned to the SchematronResource itself. Please see https://github.com/phax/ph-schematron/blob/master/ph-schematron/src/test/java/com/helger/schematron/supplementary/Issue30Test.java for a working test case that fixes the Entity resolution and the error handling logging.

phax commented 8 years ago

Did the EntityHandler extension help you? Do you need a 4.1.1 release?

jkiddo commented 8 years ago

Release early, release often ;) - I found a workaround, so it is not that critical. But feel free to push a release when you see fit containing the fix

phax commented 8 years ago

Version 4.1.1 is on Maven central