You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Huw Roberts <hu...@irisfinancial.com> on 2004/12/23 02:10:33 UTC
Help required - Failing to re-use XMLReader schema validation
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-noNa
mespaceSchemaLocation", "/com/iris/csl/service/services.xsd");
EntityResolver resolver = new
XmlElementUtil.JavaResourceEntityResolver(xmlReader.getClass().getClassLoade
r());
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.
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
Re: Help required - Failing to re-use XMLReader schema validation
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hello Huw,
In Xerces 2.6.2 (probably dating back to 2.6.0) there was a bug [1]
affecting the schema location properties which caused their values to be
ignored on subsequent parses if the parser configuration isn't changed.
The problem has been fixed in CVS.
[1] http://issues.apache.org/jira/browse/XERCESJ-994
"Huw Roberts" <hu...@irisfinancial.com> wrote on 12/22/2004 08:10:33
PM:
> 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);
> //...
>
> 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.
> 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
>
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org