You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Steve Appling <ja...@appling.org> on 2002/04/18 14:31:39 UTC

JSTL x:parse problems

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.


Re: JSTL x:parse problems

Posted by peter lin <pe...@labs.gte.com>.
The code that handles it does perform type checking, so it should work.
the code below is taken from the parsesupport.

	if (xmlUrl != null)
	    d = parseURLWithFilter(xmlUrl, filter);
	else {
	    if (xmlText instanceof String)
		d = parseStringWithFilter((String) xmlText, filter);
	    else if (xmlText instanceof Reader)
		d = parseReaderWithFilter((Reader) xmlText, filter);
	    else
		throw new JspTagException(
		    Resources.getMessage("PARSE_INVALID_SOURCE"));
	}

can you post and example of the XML, it could be the XML isn't valid.

peter

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" <pe...@labs.gte.com>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> 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:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> >
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL x:parse problems

Posted by peter lin <pe...@labs.gte.com>.
I looked at your code again and had a thought. It's not getting it from
the pagecontext.

try this instead.

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


peter

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" <pe...@labs.gte.com>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> 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:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> >
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL x:parse problems

Posted by Shawn Bayern <ba...@essentially.net>.
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" <pe...@labs.gte.com>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> 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:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> >
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL x:parse problems

Posted by Steve Appling <ja...@appling.org>.
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" <pe...@labs.gte.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
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:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL x:parse problems

Posted by peter lin <pe...@labs.gte.com>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>