Project

Profile

Help

Bug #2599

closed

Schema validation errors are not reported through ErrorHandler

Added by Radu Pisoi about 8 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Low
Category:
-
Sprint/Milestone:
-
Start date:
2016-01-26
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.7
Fix Committed on Branch:
9.7
Fixed in Maintenance Release:
Platforms:

Description

With the latest Saxon 9.7.0.2, not all the schema validation errors are not reported through the org.xml.sax.ErrorHandler interface. I'm using the SchemaFactory JAXP API for validating an XML instance against an XML Schema .

I can reproduce the problem by running the next Java Class:

public class SchemaValidation {
	/**
	 * Error handler for collecting Saxon validation errors.
	 */
	private static ErrorHandler errorHandler = new ErrorHandler() {
		@Override
		public void warning(SAXParseException we) throws SAXException {
			System.out.println("Warning: " + we);
		}
		@Override
		public void fatalError(SAXParseException fe) throws SAXException {
			System.out.println("Fatal error: " + fe);
		}
		@Override
		public void error(SAXParseException ee) throws SAXException {
			System.out.println("Error: " + ee);
		}
	};

	public static void main(String[] args) throws SAXException, FileNotFoundException, IOException {
		File schemaFile = new File("samples/validation/personal.xsd");
		File xmlFile = new File("samples/validation/personal-schema.xml");
		
		SchemaFactoryImpl schemaFactory = new com.saxonica.ee.jaxp.SchemaFactoryImpl();

		// Set error handler
		schemaFactory.setErrorHandler(errorHandler);

		// Strict schema validation
		schemaFactory.setProperty(FeatureKeys.SCHEMA_VALIDATION, Validation.STRICT);
		Schema schema = schemaFactory.newSchema(schemaFile);
		Validator newValidator = schema.newValidator();
		newValidator.setErrorHandler(errorHandler);
		newValidator.validate(new SAXSource(new InputSource(new FileInputStream(xmlFile))));
	}
}

In my case, only one error is reported through ErrorHandler:

One or more validation errors were reported

The other errors are only visible in the console (System.err) without being reported through the error handler.


Files

personal.xsd (5.18 KB) personal.xsd Radu Pisoi, 2016-01-26 14:38
personal-schema.xml (312 Bytes) personal-schema.xml Radu Pisoi, 2016-01-26 14:38
Actions #1

Updated by O'Neil Delpratt about 8 years ago

  • Status changed from New to In Progress
  • Assignee set to O'Neil Delpratt
  • Found in version deleted (9.7.0.2)
  • Applies to branch 9.7 added
Actions #2

Updated by O'Neil Delpratt about 8 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100
  • Fix Committed on Branch 9.7 added

With the changes in Saxon 9.7 where we now report validation error via a InvalidityHandler we had not probably handled wrapping a ErrorHandler supplied by the user via JAXP API.

Bug fix applied in the ValidatorImpl class. The fix was to create a InvalidityHandler wrapper class for the ErrorHandler and set this on the PipelineConfiguration.

Actions #3

Updated by O'Neil Delpratt about 8 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.7.0.3 added

Bug fix applied in the Saxon 9.7.0.3 maintenance release.

Please register to edit this issue

Also available in: Atom PDF