Project

Profile

Help

Bug #2599

closed

Schema validation errors are not reported through ErrorHandler

Added by Radu Pisoi almost 9 years ago. Updated almost 9 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

Please register to edit this issue

Also available in: Atom PDF