xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "anthony.dodd" <anthony.d...@ntlworld.com>
Subject XMLValidator - how to specify schemaLocation attribute if schema contained in a jar file
Date Sat, 02 Sep 2000 20:22:18 GMT
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(XMLValidator.java:2049)
        at org.apache.xerces.validators.common.XMLValidator.bindNamespacesToElementAndAttributes(XMLValidator.java:1911)
        at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:697)
        at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1852)
        at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.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 ) {
                file://System.out.println("loc = "+loc);
                file://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 getClass().getResouceAsStream()
for example to reference the schema. 

Thanks in advance for any help with this issue.

Regards
Tony Dodd 

   

Mime
View raw message