The reason that the entity resolver is not called is that in the case there
is no xsi:schemaLocaiton in the instance, both system id and public id
would be null, then most applications wouldn't know what to do with them.
This is why the parser decides not to call the entity resolver.

2 ways to solve your problem:

1. Use grammar preparsing/caching. This not only solves your problem, but
greatly improve the performance if the same schema is used over and over.
You preparse the schema, store it in a grammar pool, and set that pool to
the parser. This way, the parser knows how to find your schema. For more
information, please refer to the grammar faq [1].
2. Interact with XNI instead of SAX/DOM/JAXP. Register an
XMLEntityResolver, which gets called when the parser needs a schema. It
gets more information then just the system/public ids. It also gives your
the namespace of the schema and why the parser needs it (referenced by the
instance, imported/included by another schema document, etc.) Searching the
mailing list archive for "XMLEntityResolver" would give you more detail.

[1] http://xml.apache.org/xerces2-j/faq-grammars.html

Hope this helps,
Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
[EMAIL PROTECTED]



                                                                                
                                                       
                      "Kumaravel"                                               
                                                       
                      <[EMAIL PROTECTED]        To:       <[EMAIL PROTECTED]>, 
<[EMAIL PROTECTED]>                         
                      ance.com>                cc:                              
                                                       
                                               Subject:  Re: EntityResolver for 
XSD                                                    
                      11/21/2002 11:47                                          
                                                       
                      AM                                                        
                                                       
                      Please respond to                                         
                                                       
                      xerces-j-user                                             
                                                       
                                                                                
                                                       
                                                                                
                                                       




 Hi,
  Thanks for your response. I could get some information from your reply.
But I need few clarification. I have to validate the attched XML against
the
attached XSD. The XML file come to the validator through some other
application. The incoming XML look like the attached one. It does not have
xsi:schemaLocation = . But, some other means, I know that the incoming XML
has to be validated against the remote XSD. (attached for reference). As
your suggested I attached the entity resolver with the XMLReader. When I
run
the program the following error is appearing.

Error: General Schema Error: Grammar with uri:
http://www.tibco.com/xmlns/ae2xsd/2002/05/ae/test/display , can not be
found; schema namespace may be wrong:  Xerces supports schemas from the
"http://www.w3.org/2001/XMLSchema"; namespace or the instance document's
namespace may not match the targetNamespace of the schema.

The interesting part is entity resolver is not at all called to load the
schema.

If I add the xsi:schemaLocation in the XML, it works fine. It calls the
entity resolver to resolve the schema. But my requirement is to validation
with out xsi;schemaLocation.

Could you please suggest anything...???

Cheers
Kumaravel


----- Original Message -----
From: "Dean Des Rosiers" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 21, 2002 12:06 AM
Subject: RE: EntityResolver for XSD


> I've implemented a very simple EntityResolver.  It pulls the xsd from an
> EntityBean, if you can imagine such a thing!  It's possible that this
code
> is no good or even dangerous.  I'll leave it to the better minds on this
> list to determine that.  I contribute this code because I've gotten a lot
of
> info from this list and I'd like to "give back."
>
> Here's the code...
>
> public class DataSetSchemaResolver implements EntityResolver
> {
>   public InputSource resolveEntity(String publicId, String systemId)
>     throws SAXException, IOException
>   {
>     try
>     {
>       String descriptiveId = systemId;
>       int dotLoc = systemId.indexOf('.');
>       if (dotLoc > -1)
>         descriptiveId = systemId.substring(0, systemId.indexOf('.'));
>
>       DataSetSchemaLocal schema =
>
(DataSetSchemaLocal)getSchemaHome
().findByDescriptiveIdLatest(descriptiveId)
> ;
>       if (schema != null)
>       {
>         InputSource inputSource = new InputSource(new
> StringReader(schema.getXmlText()));
>         inputSource.setPublicId(publicId);
>         inputSource.setSystemId(systemId);
>         return inputSource;
>       }
>       else
>       {
>         throw new SAXException("Couldn't find " + systemId);
>       }
>     }
>     catch (Exception e)
>     {
>       throw new SAXException(e);
>     }
>
>   }
>
>
> Hope this helps.
> Dean
>
> Hi,
>   Can any one give some information about EntityResolver to load the XSD
> from some where else. Any reference or code samples...??
>
> Cheers
> Kumar
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

#### kumar.xml has been removed from this note on November 21 2002 by Sandy
Gao
#### input.xsd has been removed from this note on November 21 2002 by Sandy
Gao



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to