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 Tom Mortimer <to...@lemurconsulting.com> on 2002/09/04 17:50:58 UTC

DOCTYPE and EntityResolver problems

Hi,

I've searched the archives (and Google groups) for an answer to this, 
but not found anything that works.. anyway..

I'm using Xerces 2.1.0, and have a simple XML parser app where I want to 
store the DTD internally. I thought I could do this by registering an 
EntityResolver, like this:

    parser = XMLReaderFactory.createXMLReader
        ("org.apache.xerces.parsers.SAXParser");

    // set content handler etc
    // ...
 
    parser.setEntityResolver (new EntityResolver() {
        public InputSource resolveEntity (String publicId, String systemId)
            throws SAXException, IOException
        {
              System.out.println ("resolveEntity: " + systemId);
              if (systemId.equals ("aardvark")) {
                   // return an InputSource
              } else {
                return null;
              }
         }           
    });

and specifying my doctype in the XML file:

    <!DOCTYPE aardvark SYSTEM "aardvark">

However, when I run this, resolveEntity() is never called (and instead I 
get a FileNotFoundException.)

What am I doing wrong to prevent the EntityResolver being used?

Thanks!
Tom



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


Re: DOCTYPE and EntityResolver problems

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi Tom,

This should work; I am doing something very similar.

If I remember correctly, there was a bug in xerces a few versions ago
which stopped resolveEntity from being called if there was no public id.
If you are using an older version, I suggest you try upgrading (or
putting in a public id).

Cheers,

Simon.

On Thu, 2002-09-05 at 03:50, Tom Mortimer wrote:
> Hi,
> 
> I've searched the archives (and Google groups) for an answer to this, 
> but not found anything that works.. anyway..
> 
> I'm using Xerces 2.1.0, and have a simple XML parser app where I want to 
> store the DTD internally. I thought I could do this by registering an 
> EntityResolver, like this:
> 
>     parser = XMLReaderFactory.createXMLReader
>         ("org.apache.xerces.parsers.SAXParser");
> 
>     // set content handler etc
>     // ...
>  
>     parser.setEntityResolver (new EntityResolver() {
>         public InputSource resolveEntity (String publicId, String systemId)
>             throws SAXException, IOException
>         {
>               System.out.println ("resolveEntity: " + systemId);
>               if (systemId.equals ("aardvark")) {
>                    // return an InputSource
>               } else {
>                 return null;
>               }
>          }           
>     });
> 
> and specifying my doctype in the XML file:
> 
>     <!DOCTYPE aardvark SYSTEM "aardvark">
> 
> However, when I run this, resolveEntity() is never called (and instead I 
> get a FileNotFoundException.)
> 
> What am I doing wrong to prevent the EntityResolver being used?
> 
> Thanks!
> Tom
> 
> 
> 
> ---------------------------------------------------------------------
> 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