• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JSTL: Help needed in retrieving data from xml, setting it and printing

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am reading the contents of an xml file in my jsp through the jstl xml tags. How do i retrieve the data and set it into another variable, so that i can use it to either output on the browser or set in the html input tag.

I tried the below, but it does not work. The xml document is in the memory in request scope (xmlDoc)

<x:choose>
<x:when select="$xmlDoc/document/validation/flag[text()='N']">
<x:set var="name" select="$xmlDoc/document/names/firstName"/>
</x:when>

<x:otherwise>
<x:set var="name" select="$xmlDoc/document/names/lastName"/>
</x:otherwise>
</x:choose>
<b><c:out value="${name}"/></b>
<input type="hidden" name="name-text" value="${name}"/>

Assume that the condition is not satisfied and it goes into the 'otherwise' loop. I verified this by putting a c: out in both the 'when' and 'otherwise' clause and 'otherwise' got executed. c:out for name displays question: null
The same value gets displayed for the value of the input tag.

If I change the select to $xmlDoc/document/names/firstName/text(), then c:out displays #text: ABC (i.e the value present for the element node question.

Could someone please let me know what is wrong and how do i correct it ?
I do not want to use x:out tag and input html tag in both 'when' and 'otherwise' loop.

Thanks.
 
lavi mendonca
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out the mistake.

Should be using <x:out select="$var"/>
 
I think she's lovely. It's this tiny ad that called her crazy:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic