commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [Digester] How to turn off parse's attempt to retrieve dtd?
Date Wed, 15 Jun 2005 08:31:42 GMT
Hi Jon,

On Wed, 2005-06-15 at 03:36 -0400, Jon Steelman wrote:
> When I parse after setValidating(false), why does Digester still try to
> retrieve the dtd file? What else do I need to set in Digester to make it
> ignore xml like <!DOCTYPE cardActionVendor SYSTEM
> "cardActionVendor.dtd"> ? Otherwise, I cannot parse and if I don't have
> the dtd at the moment and always get the java.io.FileNotFoundException
> (The system cannot find the file specified). Using Digester 1.7.

This is standard XML parser behaviour. Even when validation is disabled,
an XML parser still needs the DTD for things such as entity definitions.

Digester provides basic support for using local copies of resources
referenced from an xml file (such as DTDs): if your DOCTYPE declaration
was properly formed (ie had a PUBLIC declaration instead of just a
SYSTEM declaration) then you could have used the Digester.register
method to register a local copy of the DTD for the PUBLIC id. Note that
omitting the PUBLIC id from a DTD decl is WRONG in any application where
xml is expected to be used on a host other than the one it is created
on.

But as you've got a broken DOCTYPE you have two options:
(1) use some parser-specific property setting to tell the parser to
ignore external DTDs. If you're using Sun's java 1.4 or later then the
underlying parser is actually Xerces, so see 
  http://xml.apache.org/xerces2-j/features.html
  for feature external-parameter-entities
and see also method Digester.setProperty. Of course this isn't terribly
portable, nor guaranteed to work in future JVMs (though I can't see Sun
ditching Xerces for anything else in the near future).

(2) write a custom EntityResolver subclass that returns an empty stream
when asked for the DTD, and register that with Digester using
Digester.setEntityResolver.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message