Using Xeces 1.1.3, I'm attempting to validate and XML instance document
contained in a jar file against a schema contained in the same package in
the same jar file.The problem I'm encountering is how to I specify the
schemaLocation attribute on the instance document. I've tried several
permutations, none of which work. XMLValidator.class consistently reports
file not found. 
For example the two file myxml.xml and myschema.xsd are located in package 
com.mycompany.files 
in the same jar file. The jar file is in the classpath. If I specify the xml
instance document using the the following schemaLocation attribute 
xsi:schemaLocation="http://www.mycompany.com
/com/mycompany/files/myschema.xsd" 
I get the following error message and exception 
        [Error] :1:213: General Schema Error: Stopping after fatal error:
File "<file:///com/mycompany/files/myschema.xsd>" not found..
        java.lang.NullPointerException
        at
org.apache.xerces.validators.common.XMLValidator.resolveSchemaGrammar(XMLVal
idator.java:2049)
        at
org.apache.xerces.validators.common.XMLValidator.bindNamespacesToElementAndA
ttributes(XMLValidator.java:1911)
        at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidat
or.java:697)
        at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanne
r.java:1852)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
LDocumentScanner.java:1000)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
java:380)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:861)
        at
com.synergy.xml.wrappers.NonValidatingDOMParser.parse(NonValidatingDOMParser
.java:103)
        at com.synergy.rules.SRule.getRuleDocument(SRule.java:108)
        at SLoadRulesFrameWork.<init>(SLoadRulesFrameWork.java:24)
        at SLoadRulesFrameWork.main(SLoadRulesFrameWork.java:36)
        <http://www.mycompany.com> grammar not found 
Looking at XMLValiadator.java and the way in which it uses the
DefaultEntityHandler's expandSystemId function it appears that it expects
the schema to be on the file system, and not as in my case wrapped up in a
jar file. I've included the code from lines 2036 to 2039 of XMLValidator to
illustrate the point. 
        if (source == null) {
        loc = fEntityHandler.expandSystemId(loc);
        source = new InputSource(loc);
        }
        try {
        parser.parse( source );
        }catch( IOException e ) {
        e.printStackTrace();
        }catch( SAXException e ) {
        System.out.println("loc = "+loc);
        e.printStackTrace();
        reportRecoverableXMLError( XMLMessages.MSG_GENERIC_SCHEMA_ERROR, 
        XMLMessages.SCHEMA_GENERIC_ERROR, e.getMessage() );
        } 
It's quite possible that I've misinterpreted the code, but is there any way
in which I could specify the EntityHandler used by XMLValidator so that I
could use Class.getResouceAsStream() for example to reference the schema. 
Thanks in advance for any help with this issue. 
Regards 
Tony Dodd 

Reply via email to