Thanks a bunch.  I had wondered if the InputSource that was supposed to be
returned from the resolveEntity was for the XML file itself, or for the DTD,
in which case the parser had already created another separate InputSource
for the XML file.  This makes more sense now.  However, I am interested in
one other detail.  I passed in the uri of the XML file to the
parser.parse(uri) method.  In the EntityResolver, I do not know what the uri
to the XML file is -- I only know the uri of the dtd (via the systemId).  I
suppose that I will have to set this at the time I create the EntityResolver
(i.e. create a constructor in the EntityResolver, pass the uri in, etc.).
However, if I am required not only to resolve the dtd in the EntityResolver,
but also create the InputSource for the xml file itself in the resolveEntity
method, wouldn't it make sense to pass the uri of the xml file itself as a
parameter to the resolveEntity method?  It seems strange that in passing
this xml uri to the parser.parse(uri) method, we not only lose this
information but need to have it supplied by some other means to the
EntityResolver.  Does this sound like a good idea?

Brad

-----Original Message-----
From: Andy Clark [mailto:[EMAIL PROTECTED]
Sent: Monday, February 19, 2001 6:20 PM
To: [EMAIL PROTECTED]
Subject: Re: EntityResolver/Windows Paths -- [ WAS: Windows Paths]


Brad O'Hearne wrote:
> However, if my xml file is c:\test\data.xml, and my dtd is
c:\dtd\data.dtd,
> and I try the following line, after it returns the XMLReader will throw a
> NullPointerException:

I haven't really looked into your problem in detail but it
sounds like the parser is assuming that you are going to
open the entity in your entity resolver. So when you just
create an InputSource object with a new system id, the
parser asks for the input stream (or reader) which is null
and this causes a NullPointerException to be thrown.

Since you know the location of your file, why don't you
open the stream yourself? For example:

  public InputSource resolveEntity(String publicId, String systemId)
    throws SAXException, IOException {

    // we know the location of this entity
    if (systemId.endsWith("data.dtd")) {
      InputStream stream = new FileInputStream("c:\\test\\data.dtd");
      InputSource source = new InputSource(stream);
      source.setPublicId(publicId);
      source.setSystemId(systemId);
      return source;
    }

    // can't resolve, let parser try to find it
    return null;
  }

--
Andy Clark * IBM, TRL - Japan * [EMAIL PROTECTED]

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

Reply via email to