[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-j-dev
Subject:    Help required - Failing to re-use XMLReader schema validation
From:       "Huw Roberts" <huw.roberts () irisfinancial ! com>
Date:       2004-12-23 1:10:33
Message-ID: KJEFLJBIEJGBOMOMOOGBMEEDFFAA.huw.roberts () irisfinancial ! com
[Download RAW message or body]

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

[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1479" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=375353600-23122004>Hi 
All,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=375353600-23122004>I'm having some 
trouble re-using an XMLReader that I am asking to validate some XML against a 
schema.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=375353600-23122004>An example of the 
sort of code I'm using is as follows:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=375353600-23122004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
//...</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
XMLReader xmlReader = 
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 xmlReader.setFeature("<A 
href="http://apache.org/xml/features/validation/schema">http://apache.org/xml/features/validation/schema</A>", \
 true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlReader.setFeature("<A 
href="http://xml.org/sax/features/validation">http://xml.org/sax/features/validation</A>", \
 true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlReader.setProperty("<A 
href="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation">http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation</A>", \
 "/com/iris/csl/service/services.xsd");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 EntityResolver resolver = new 
XmlElementUtil.JavaResourceEntityResolver(xmlReader.getClass().getClassLoader());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 xmlReader.setEntityResolver(resolver);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 ErrorHandler errorHandler = new 
XmlChecker.BasicErrorHandler();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
xmlReader.setErrorHandler(errorHandler);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 InputSource inputSource;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("parse one");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
inputSource = new InputSource(new 
StringReader("&lt;CSLSystem/&gt;"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
xmlReader.parse(inputSource);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("parse two");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
inputSource = new InputSource(new 
StringReader("&lt;CSLSystem/&gt;"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
xmlReader.parse(inputSource);<BR>
<DIV><FONT face=Arial size=2><SPAN 
class=375353600-23122004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
//...</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=375353600-23122004></SPAN></FONT>&nbsp;</DIV></FONT></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>Interesting features 
of this code are:</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2><SPAN 
class=375353600-23122004><FONT face=Arial size=2>1.&nbsp; The 
XmlChecker.BasicErrorHandler simply prints errors/warnings/fatal to 
stdout</FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>2.&nbsp; I get 
different error messages from the two calls to 
xmlReader.parse:</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; 
parse one<BR>&nbsp;&nbsp;&nbsp; org.xml.sax.SAXParseException: 
cvc-complex-type.2.4.b: The content of element 'CSLSystem' is not complete. One 
of '{"":type, "":configuration}' is expected.<BR>&nbsp;&nbsp;&nbsp; parse 
two<BR>&nbsp;&nbsp;&nbsp; org.xml.sax.SAXParseException: cvc-elt.1: Cannot find 
the declaration of element 'CSLSystem'.<BR></FONT></SPAN><SPAN 
class=375353600-23122004><FONT face=Arial size=2>3.&nbsp; I have a custom entity 
resolver which is only called during the first call to 
parse.</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>4.&nbsp; Is it 
conceivable that the problem might be in 
org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar?</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; 
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...?</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial size=2>Thanks 
all,</FONT></SPAN></DIV>
<DIV><SPAN class=375353600-23122004><FONT face=Arial 
size=2>Huw</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=375353600-23122004></SPAN></FONT>&nbsp;</DIV></BODY></HTML>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic