Recently I have been using Will’s libary for processing XML files in at request time using JSTL, and thought i would post some working examples which may be of use.
This example traverses into all folders below the ‘partner-data’ folder and matches all XML documents with the root element pe:partner_entrance:
<c:forEach items="${alfxml:getXMLDocuments(pageContext, '/partner-data/', true, '/pe:partner_entrance', '', 1)}" var="ent">
<c:choose>
<c:when test="${ent['/pe:partner_entrance/pe:name']==param.name}">
<p>Name - <c:out value="${ent['/pe:partner_entrance/pe:name']}" /></p>
</c:when>
</c:choose>
</c:forEach>
The second example loads a single XML document and creates an HTML drop down list item. It matches on the “code” item and prints the name for each element:
<c:set value="${alfxml:getXMLDocument(pageContext, '/map_data.xml')}" var="md" />
<form id="criteria" name="criteria" method="GET" action="test.jsp">
<select name="region" id="region">
<option value="" selected="selected">Please Select</option>
<c:forEach items="${md['/mapdata/regions/region/@code']}" var="ccode">
<c:set var="key" value="/mapdata/regions/region[@code='${ccode}']/@name" />
<c:set var="cname" value="${md[key]}" />
<option value="<c:out value='${ccode}' />"><c:out value="${cname}" /></option>
</c:forEach>
</select>
{ 0 comments… add one now }