Thanks Craig!  I think the problem was indeed that I was using
digester.parse(InputStream) instead of digester.parse(InputSource).  I may
submit a patch for the digester documentation to give a brief description of
why this is necessary when validating against system DTDs.

I'll have to do more testing once this east coast hurricane passes... the
Internet is acting weird in DC.

Matt
----- Original Message ----- 
From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
To: "Jakarta Commons Users List" <[EMAIL PROTECTED]>
Sent: Thursday, September 18, 2003 12:03 PM
Subject: Re: [digester] validating against system dtd?


> On Thu, 18 Sep 2003, Sgarlata Matt wrote:
>
> > Date: Thu, 18 Sep 2003 09:02:28 -0400
> > From: Sgarlata Matt <[EMAIL PROTECTED]>
> > Reply-To: Jakarta Commons Users List <[EMAIL PROTECTED]>
> > To: [EMAIL PROTECTED]
> > 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();
>   is.setByteStream(input);
>   digester.parse(is);
>   input.close();
>
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to