[jdom-interest] How to supress external DTD error

Tatu Saloranta cowtowncoder at yahoo.com
Sun Nov 27 20:10:39 PST 2005


Andrew Zahra <andrew.zahra at gmail.com> wrote: I am trying to parse a simple document being sent to me over TCP. I am using the SAXBuilder class with its default constructor. Problem is the XML doc I am receiving specifies a DTD. Even though I am not validating the document I get an error saying that the external DTD file is not found.
   
 
 If I create an empty DTD file it is happy, but I don't want to do this.
 
 Is there any way I can stop it trying to open the external DTD or supress the error and make it continue?
 
 I did try using setErrorHandler with an error handler that just returned on error but that didn't work.
The reason SAX parser tries to read the DTD nonetheless is since it might contain parsed entities that may be referenced by the document. Some parsers do this lazily, ie. only if they encounter an unknown entity.
 There are ways around this problem, the simplest is probably to just create a dummy EntityResolver that just resolves any references to the external DTD to return empty content (or anything that's valid DTD; this should be easy): this should resolve your problem.
 
 Another possibility would be using parsers where DTD support can be disabled; StAX parsers for example have a property to use that completely disables handling of DTDs. ;-)
 (I wrote StAXBuilder that can be used to build JDom documents using a StAX XMLStreamReader).
 
 -+ Tatu +-
 
 


		
---------------------------------
 Yahoo! Personals
 Single? There's someone we'd like you to meet.
Lot's of someone's, actually. Yahoo! Personals
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20051127/f00ce7f9/attachment.htm


More information about the jdom-interest mailing list