On Fri, 21 Mar 2003, Jeff Caddel wrote:

> Date: Fri, 21 Mar 2003 05:38:54 -0700
> From: Jeff Caddel <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: Struts Users Mailing List <[EMAIL PROTECTED]>
> Subject: Digester Best Practice
>
> Any reasons for one of these approaches being better/worse than the other?
>
>  URL url =
> Thread.currentThread().getContextClassLoader().getResource("/WEB-INF/test.xml");
>
>  InputStream input = url.openStream();
>  Digester digester = new Digester();
>  digester.parse(input);
>
>
>  URL url =
> Thread.currentThread().getContextClassLoader().getResource("/WEB-INF/test.xml");
>
>  InputSource is = new InputSource(url.toExternalForm());
>  is.setByteStream(input);
>  InputSream input = url.openStream();
>  Digester digester = new Digester();
>  digester.parse(is);
>
>
> ActionServlet does it the second way (InputSource), Tiles code does it
> the first way (InputStream).  I ran into a problem getting Digester to
> parse xml documents that use "includes" with the InputStream method:
>
> <!DOCTYPE xxx PUBLIC "-//xx//xx 1.0//EN" "http://localhost/my-dtd.dtd"; [
> <!ENTITY users SYSTEM "users.xml">
> ]>
> <my-xml>
>      &users;
> </my-xml>
>
> It throws "org.xml.sax.SAXParseException: Relative URI "users.xml"; can
> not be resolved without a base URI."
> Switching to the InputSource method let Digester do it's thing, but I'm
> unclear on why.
>

The reason Struts does it the second way is to make includes work :-).

Consider what the XML parser has to do when it sees the "&users;" entity,
and you're using the first form:

    "Aha, I need to go find the 'users.xml' document and insert
    it here.  OK, 'users.xml' is a relative path, so I need to
    resolve it relative to the absolute path of the containing
    document.  And the URL for that is .... ooops ..."

Using the second form, with an InputSource, lets Struts say "the absolute
URL of the containing document is xxxxx", so that relative URLs can be
resolved correctly.

Craig

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

Reply via email to