Skip to main content

StAX: validating and parsing in one step.

No replies
Joined: 2010-06-10


I have seen these examples for validating StAX input

They all have in common that they validate the input in one step and process the data in a second step. This means the input is completely read once for validation and then again for processing, which seems rather ineffective to me. With SAX, I can do this:

public void parse(InputStream input, ContentHandler handler) throws SAXException, IOException {
InputSource is = new InputSource(input);

Validator v = schemaFactory.newSchema().newValidator();
v.setResourceResolver(schemaFactory.getResourceResolver()); // use my own schema resolver

v.validate(new SAXSource(is), new SAXResult(handler));

Is there a way to have a StAX parser that validates on the fly and uses my own schema resolver?