[jdom-interest] builder.setIgnoreDTD()

Jason Hunter jhunter at servlets.com
Tue Feb 5 21:48:17 PST 2002

One thing on the TODO list is to add a builder.setIgnoreDTD() flag which
people can set if they want the builder to not read the external DTD. 
Normally parsers do read external DTDs even when validation is off,
because they look for entities and such, and a lot of people find this
bothersome for offline work and such.

It's been mentioned this can be accomplished using an EntityResolver. 
For example, I have success using the following:

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import java.io.*;

public class NoOpEntityResolver implements EntityResolver {
  public InputSource resolveEntity(String publicId, String systemId) {
    return new InputSource(new StringBufferInputStream(""));

And in the builder calling:

builder.setEntityResolver(new NoOpEntityResolver());

So I'm thinking perhaps we should have setIgnoreDTD() automatically set
this entity resolver.  I to remember someone (Brett?) warning there was
a problem with this.  Perhaps the problem is that if you wanted to
actually resolve entities, you'd need to have something smarter than
this resolver.

So the question is, what are the problems with this approach, and should
we (a) implement setIgnoreDTD() as above or just (b) add an entry in the
FAQ about this.  Or is there a (c) better option.  Like in Xerces they
have a feature
http://apache.org/xml/features/nonvalidating/load-external-dtd, but in
Crimson and other parsers there's no counterpart last I checked.

Opinions welcome.


More information about the jdom-interest mailing list