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 Kumaravel <nk...@aalayance.com> on 2002/11/20 11:47:03 UTC

EntityResolver for XSD

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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: EntityResolver for XSD

Posted by Kumaravel <nk...@aalayance.com>.
 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" <de...@desropolis.com>
To: <xe...@xml.apache.org>
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: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>

RE: EntityResolver for XSD

Posted by Dean Des Rosiers <de...@desropolis.com>.
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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org



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