Hi
All,
I'm having some
trouble re-using an XMLReader that I am asking to validate some XML against a
schema.
An example of the
sort of code I'm using is as follows:
//...
XMLReader xmlReader =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
xmlReader.setFeature("http://apache.org/xml/features/validation/schema", true);
xmlReader.setFeature("http://xml.org/sax/features/validation", true);
xmlReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "/com/iris/csl/service/services.xsd");
EntityResolver resolver = new XmlElementUtil.JavaResourceEntityResolver(xmlReader.getClass().getClassLoader());
xmlReader.setEntityResolver(resolver);
ErrorHandler errorHandler = new XmlChecker.BasicErrorHandler();
xmlReader.setErrorHandler(errorHandler);
InputSource inputSource;
System.out.println("parse one");
inputSource = new InputSource(new StringReader("<CSLSystem/>"));
xmlReader.parse(inputSource);
System.out.println("parse two");
inputSource = new InputSource(new StringReader("<CSLSystem/>"));
xmlReader.parse(inputSource);
xmlReader.setFeature("http://apache.org/xml/features/validation/schema", true);
xmlReader.setFeature("http://xml.org/sax/features/validation", true);
xmlReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "/com/iris/csl/service/services.xsd");
EntityResolver resolver = new XmlElementUtil.JavaResourceEntityResolver(xmlReader.getClass().getClassLoader());
xmlReader.setEntityResolver(resolver);
ErrorHandler errorHandler = new XmlChecker.BasicErrorHandler();
xmlReader.setErrorHandler(errorHandler);
InputSource inputSource;
System.out.println("parse one");
inputSource = new InputSource(new StringReader("<CSLSystem/>"));
xmlReader.parse(inputSource);
System.out.println("parse two");
inputSource = new InputSource(new StringReader("<CSLSystem/>"));
xmlReader.parse(inputSource);
//...
Interesting features
of this code are:
1. The
XmlChecker.BasicErrorHandler simply prints errors/warnings/fatal to
stdout
2. I get
different error messages from the two calls to
xmlReader.parse:
parse one
org.xml.sax.SAXParseException: cvc-complex-type.2.4.b: The content of element 'CSLSystem' is not complete. One of '{"":type, "":configuration}' is expected.
parse two
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'CSLSystem'.
3. I have a custom entity resolver which is only called during the first call to parse.
org.xml.sax.SAXParseException: cvc-complex-type.2.4.b: The content of element 'CSLSystem' is not complete. One of '{"":type, "":configuration}' is expected.
parse two
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'CSLSystem'.
3. I have a custom entity resolver which is only called during the first call to parse.
4. Is it
conceivable that the problem might be in
org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar?
It appears to call XMLSchemaLoader.resolveDocument only the first time, yet it
appears not to be able to find the schema declaration on subsequent
calls...?
Thanks
all,
Huw