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 Sean McCauliff <sm...@jareva.com> on 2002/09/19 20:15:04 UTC

EntityResolver Problems

I want to package some schemas into a jar file to avoid having the user 
need to have a magic directory that they point to that contains the 
schemas.   So I implemented an EntityResolver, but I am still getting 
errors.  The XML file that I am reading contains references to the
following schemas:  XMLSchema.xsd,  xhtml1-strict.xsd and iface2.xsd  Is 
there something that I am doing wrong? Is this a bug?

Xerces-J 2 Version: 2.1.0
JDK  1.4.1 RC1

Thanks,
-Sean


------------------------ Code --------------------------------
class MyEntityResolver extends DefaultHandler {
    public InputSource resolveEntity(String publicId, String systemId) 
throws SAXException {
        System.out.println("---->resolveEntity:" + publicId + " " + 
systemId);
        if (systemId == null) return super.resolveEntity(publicId, 
systemId);
        String orig_sys_id = systemId;
       
        //extract the real entity name / is ok because it is a url
        int i = systemId.lastIndexOf('/');
        if (i != -1 && systemId.length() != i) {
            systemId = systemId.substring(i+1,systemId.length());
        }
       
        System.out.println("----> new sys id is " + systemId);
       
        try {
            URL url = getClass().getResource("/"+systemId);
          
            if (url == null)  {
                System.out.println("----> Still nothing.");
                return super.resolveEntity(publicId,orig_sys_id);
            }
           
            System.out.println("----> found resource " + url.toString());
            InputStream is = url.openStream();
          
            System.out.println("----> input stream is " + is);
            //new Exception().printStackTrace();
            return new InputSource(is);

        } catch (IOException ioe) {
            System.out.println("Having trouble finding " + systemId +
                ", probably a CLASSPATH problem.");
            return super.resolveEntity(publicId, orig_sys_id);
        }
    }
    }


----------------  Output ----------------------------------
---->resolveEntity:null file:///home/sean/cvs/main/src/util/iface2.xsd
----> new sys id is iface2.xsd
----> found resource file:/home/sean/interface/iface2.xsd
----> input stream is java.io.BufferedInputStream@1b8e059
---->resolveEntity:null 
file:///home/sean/cvs/main/src/util/xhtml1-strict.xsd
----> new sys id is xhtml1-strict.xsd
----> found resource file:/home/sean/interface/xhtml1-strict.xsd
----> input stream is java.io.BufferedInputStream@12d3205
---->resolveEntity:null http://www.w3.org/2001/xml.xsd
----> new sys id is xml.xsd
----> found resource file:/home/sean/interface/xml.xsd
----> input stream is java.io.BufferedInputStream@6e293a
Warn: null : L33C56 :src-import.0: Failed to read imported schema 
document 'null'.
---->resolveEntity:null file:///home/sean/cvs/main/src/util/XMLSchema.xsd
----> new sys id is XMLSchema.xsd
----> found resource file:/home/sean/interface/XMLSchema.xsd
----> input stream is java.io.BufferedInputStream@1a9334
Warn: null : L10C93 :src-import.0: Failed to read imported schema 
document 'null'.
Error: null : L303C35 :src-resolve: Cannot resolve the name 'xml:lang' 
to a(n) attribute declaration component.

[output truncated]




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org