[jdom-interest] How to supress external DTD error
Andrew Zahra
andrew.zahra at gmail.com
Mon Nov 28 16:36:33 PST 2005
Thanks, that worked. I created a dummy EntityResolver as follows and then
used setEntityResolver on the SAXBuilder:
import java.io.IOException;
import java.io.StringReader;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class DummyEntityRes implements EntityResolver
{
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
return new InputSource(new StringReader(" "));
}
}
On 28/11/05, Tatu Saloranta <cowtowncoder at yahoo.com> wrote:
>
> *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<http://us.rd.yahoo.com/evt=36108/*http://personals.yahoo.com+%0D%0A>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20051129/6fad776c/attachment.htm
More information about the jdom-interest
mailing list