Reader is fine...

Your problem comes from a simple error that everyone (including me) makes
from time to time when testing JSTL with scriptlets.  Look at your sample
carefully:

 <%
  InputStream is = application.getResourceAsStream("/test.xml");
  InputStreamReader reader = new InputStreamReader(is);
 %>
 <x:parse xmlText="${reader}" var="doc"/>

You've just created a scripting variable called "reader", but nothing ties
this scripting variable to a scoped attribute, so ${reader} *is* null.

If you add a call like pageContext.setAttribute("reader", reader), the
problem will go away.

Of course, this particular sample would be better without a scriptlet, as

  <c:import url="/test.xml" varReader="xml"/>
    <x:parse xml="${xml}" var="doc"/>
  </c:import>

but I assume that your scriptlet was just an example of Reader, not the
end-to-end intended use.  :-)

Hope that helps,

-- 
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)

On Thu, 18 Apr 2002, Steve Appling wrote:

> In section 11.2 of the JSTL 1.0 public draft specification it says that
> xmlText can take a String or a Reader.  I can't use xmlUrl (or body content
> of the parse tag) because my xml is in a section of the web application that
> is in a restricted security domain.  I can't provide authentication
> information in the url to use xmlUrl.  I probably can read the entire
> document into a single String myself, then use that in xmlText, but that
> seems somewhat silly.  If it really can take a Reader as the documentation
> states, then I would rather use that approach - I was hoping there was
> something simple I was missing that was keeping this from working.
> 
> ----- Original Message -----
> From: "peter lin" <[EMAIL PROTECTED]>
> To: "Tag Libraries Users List" <[EMAIL PROTECTED]>
> Sent: Thursday, April 18, 2002 8:42 AM
> Subject: Re: JSTL x:parse problems
> 
> 
> >
> > I think you're problem is that xmlText expects String.  Have you tried
> > xmlURL, isntead of xmlText.  here is the way I use parse, which works
> > fine.
> >
> > <c:set var="xmlurl">sample.xml</c:set>
> >
> > <x:parse var="dom">
> >   <c:import url="${xmlurl}"/>
> > </x:parse>
> >
> >
> > peter lin
> >
> >
> > Steve Appling wrote:
> > >
> > > I am having problems using the standard tag library x:parse tag using a
> > > reader.  The JSTL spec says that the xmlText attribute can take either a
> > > String or a Reader.  I am trying the following:
> > >
> > > <%
> > > InputStream is = application.getResourceAsStream("/test.xml");
> > > InputStreamReader reader = new InputStreamReader(is);
> > > %>
> > > <x:parse xmlText="${reader}" var="doc"/>
> > >
> > > This results in the following exception:
> > >     javax.servlet.ServletException: The "xmlText" attribute illegally
> > > evaluated to "null" or "" in <parse>
> > >
> > > Does anyone know how to do this?
> > >
> > > If anyone from the expert group is monitoring this, it would be really
> nice
> > > if there were usage examples for each of the tags.  Also in the 1.0
> Public
> > > Draft ALL of the examples provided for x:parse are wrong, they use an
> older
> > > syntax with a source attribute which is not allowed now.
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
> >
> >
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


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

Reply via email to