p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   JSP Basics (http://p2p.wrox.com/forumdisplay.php?f=92)
-   -   JSTL, XML query (http://p2p.wrox.com/showthread.php?t=37625)

ph3n0m January 25th, 2006 01:37 PM

JSTL, XML query
 
I have the following xml document

Code:

<item>
<title>Ali G Interviews The Beckhams</title>
<link>http://www.break.com/articles/aligbeckhams.html</link>
<pubDate>Tue, 24 Jan 2006 21:25:27 CST</pubDate>
<description>Ali G Interviews The Beckhams</description>
<enclosure url="http://media1.break.com/dnet/media/content/aligbeckhams.jpg" type="image/jpeg" length="10000"/>
</item>

and am using the following to parse through it

Code:

<c:import var="xmlfile" url="http://www.break.com/rss/rss20.asp" />
<x:parse var="doc" xml="${xmlfile}"/>
<table border="0" cellspacing="0" cellspacing="0">
<x:forEach select="$doc//item">
<tr><td><strong><a href='<x:out select="link"/>'><x:out select="title"/></a></strong><br>
<em><x:out select="pubDate"/></em><br>
<x:out select="description"/>
<c:out value="${enclosure}"/></td></tr>
</x:forEach>

My only problem is - how do I get the value for the xml tag "enclosure" since it is not in the same format as the others.

I have no control over this xml document as it is an external file - so no suggestions to change it over please :)


ph3n0m January 26th, 2006 08:11 AM

<x:out select="string(enclosure/@url)"/> - is how I pulled the url value out of the xml file, so my page now looks like this

<c:import var="xmlfile" url="url.link" />
<x:parse var="doc" xml="${xmlfile}"/>
<table border="0" cellspacing="0" cellspacing="0">
<x:forEach select="$doc//item" end="9">
<tr><td><strong><a href='<x:out select="link"/>'><x:out select="title"/></a></strong><br>
<em><x:out select="pubDate"/></em><br>
<a href='<x:out select="link"/>'><img src='<x:out select="string(enclosure/@url)"/>' alt='<x:out select="title"/>' border='0'></a></td></tr>
<tr><td>&nbsp;</td></tr>
</x:forEach>

and it works perfectly


All times are GMT -4. The time now is 02:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.