Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml in JSP page

 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, I'm a complete newbie so execuse my ignorance.
if I have an xml document that specified some text that appears in a jsp file:
lets say the xml file is like: form.xml

Now in the JSP file I want the <fn>, <ln>, <ph>, <adr> elements to be displayed in the right place and to be rendered on the server, not on the clients machine, so client side xsl is not an option.
What is the easiest way to do this? How to use this specific xml file? what code do you write to get the values of the elements and put them in the right place using server side code
Lets say we have the following html.

Thanks in advance
 
prabhakar rao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
my suggestion is to learn JSTL, there are inbuilt tags are available to read xml elements and its values. So that u can use JSTL tags and get the output.
regards
prabhakar
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice, but can you please tell me how would the code look like? Just a little snippet of code.
 
Geeta Ramasami
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
For parsing and processing XML u have so many parsers available.U can go in for Apaches parser.Apaches SAX parser provides methods use to read XML file.
Regards
Geeta
 
prabhakar rao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friend,
copy c.tld and x.tld files under Web-inf folder
and observ carefully here, I've mentioned import JSTL tag to import your xml file for e.g., my xml file name is ForEachDoc.xml then
parse your xml file by using again JSTL tag and store it in a variable called as document. Here I'm using forEach tag for my own task. but that is not required for u. But observe carefully I've used x-path notations inside forEach JSTL tag i.e, $document//a
here $document means, your xml document stored in the document varaible under that I've mentioned
//a this means I'm reading element name is 'a'
in your case u give fn, ln etc., in place of 'a'
read the code, I try my level best to reach this code. In case u didn't get me pls send your personal mail id , I can send complete documentation of JSTL.
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="x" uri="/WEB-INF/x.tld" %>
<html>
<head>
<title>JSTL: XML Support -- if</title>
</head>
<body bgcolor="#FFFFFF">
<c:import var="docString" url="ForEachDoc.xml"/>
<x arse var="document" xml="${docString}"/>
<x:forEach select="$document//a" var="att">
<x:if select="$att/d">
<x ut select="$att"/><br>
</x:if>
<br></x:forEach>
regards
prabakar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic