commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [digester] validating against system dtd?
Date Thu, 18 Sep 2003 16:03:06 GMT
On Thu, 18 Sep 2003, Sgarlata Matt wrote:

> Date: Thu, 18 Sep 2003 09:02:28 -0400
> From: Sgarlata Matt <>
> Reply-To: Jakarta Commons Users List <>
> To:
> Subject: [digester] validating against system dtd?
> Hello,
> I am having difficulty trying to tell the Digester to validate against a
> system DTD.  I am not an XML guru, but from what I can tell you do not need
> to specify a public identifier for a system DTD.  That's kind of tricky,
> because the digester's register method expects a public ID.  Here is the
> beginning of my DTD:
> <!ELEMENT lookup-bean (rules?, picklists)>
> Here is the beginning of the XML file I want validated:
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE lookup-bean SYSTEM
>  "lookup-bean_1_0.dtd">
> <lookup-bean>
> Here is what I have tried when constructing my digester:
>    URL url = this.getClass().getResource("lookup-bean_1_0.dtd");
>    digester.register("", url.toString());
> Also tried:
>    URL url = this.getClass().getResource("lookup-bean_1_0.dtd");
>    digester.register(null, url.toString());
> Also tried:
>    URL url = this.getClass().getResource("lookup-bean_1_0.dtd");
>    digester.register("lookup-bean_1_0.dtd", url.toString());
> Any ideas anyone?  Any help is much appreciated!  Thanks,

One important element (and its in code you haven't shown us here) is which
Digester.parse() method you are calling.  The one to avoid is the one that
takes an InputStream.  Why?  Because then Digester (well, it's really the
XML parser underneath) has no way to know what the URL of the document
being parsed is, and therefore cannot resolve relative references in a
system URL -- although absolute ones would still work.

Here's a snippet of code from Struts that sets up an
org.xml.sax.InputSource to be parsed, and passes on to the parser what it
needs, including the base URL (you'll need try/catch blocks of course):

  URL url = getServletContext().getResource(path);
  InputSource is = new InputSource(url.toExternalForm());
  InputStream input = getServletContext().getResourceAsStream();

The same sort of thing will work in a non-webapp context, as long as you
can acquire a URL to the base resource you are parsing, and then set up an
InputSource for it.

> Matt

Craig McClanahan

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message