I am trying to have JSP pages parse and read an XML file and then return some data in an HTML table. I'm using the JSTL libraries and have a basic understanding of them, but I apparently need help.
My first page just gets the value and passes it to the second page. The second page handles all of the processing. Here is my JSP page:
<%@page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@include file="index.jsp" %>
<% String clientID = request.getParameter("enteredID"); %>
<c:import url="npiXMLTest5.xml" var="doc" />
<x:parse varDom="dom" doc="${doc}"/>
<x:set var="srcCID" select="string($dom/npiNumbers/client/clientNum)" />
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NPI XJTL Test</title></head>
<body>
<c:set var="CID" value="<%= clientID %>" />
<h2>NPI XJTL Test Page</h2>
<table border="1">
<tr><th>NPI Number</th><th>Description</th></tr>
<c:choose>
<c:when test="${CID}=${srcCID}">
<x:forEach select="$dom/npiNumbers/client/npiNum" var="$n">
<tr><td><x:out select="$n/npi" /></td><td><x:out select="$n/desc" /></td></tr>
</x:forEach>
</c:when>
<c:otherwise>
There is an error with your coding
</c:otherwise>
</c:choose>
</table></body></html>
My XML structure is as follows:
<npiNumbers xsi:schemaLocation="http://localhost/namespace NPI_XSD5.xsd" xmlns="http://localhost/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<client>
<clientNum/>
<clientName/>
<npiNum>
<npi/>
<desc/>
</npiNum>
</client>
</npiNumbers>
I am trying to return the results of the <npiNum> element (which can have multiple values) - <npi> and <desc> - in a table based on the <clientNum> element. I try to evaluate the page variable with the xml element. If it matches, I will return a table. A client can have multiple <npiNum> elements, so the construction of the table is in the x:forEach loop.
I think my problem is getting the variable from JSP to compare against the <clientNum> element in the XML file.
Any ideas?