[jdom-interest] Parsing withou validating - File not Found

Brett McLaughlin brett at newInstance.com
Thu Jul 19 11:02:24 PDT 2001


>
> Hi there.
>
> I´m newbie in using jdom and xml, and I'm trying to parse the XML without
> validating it (i just wanna know its doctype, nothing else). To parse the
> XML i'm using a DOMBuider, but when I do a DOMBuilder.buile(string), I get

First, don't use DOMBuilder for parsing an incoming String; instead, use
SAXBuilder, which is much faster.

> an error, indicating that the dtd file could not be found. But I don´t
> want to use the dtd file, and I didn´t found a method that disables this
> search. Is there a way to parse the XML without searching and validating

Most parsers, including Xerces, will resolve the DTD reference because it
may need to be used for entity resolution. The best way to ensure that this
doesn't happen is to implement an EntityResolver:

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

public class NoDTDEntityResolver {
    public InputSource resolveEntity(String publicID, String systemID) {
        if (systemID.equals("myDTDSystemID")) {
            return null;
        }
    }
}

Then create an instance of it and pass it to SAXBuilder/SAXHandler's
setEntityResolver() method. That should take care of it.

---
Brett McLaughlin
Enhydra Strategist:   http://www.enhydra.org
Lutris Technologies: http://www.lutris.com
O'Reilly Author:       http://www.newInstance.com




More information about the jdom-interest mailing list