aspose file tools*
The moose likes JSP and the fly likes xml in JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "xml in JSP page" Watch "xml in JSP page" New topic
Author

xml in JSP page

Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
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


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
prabhakar rao
Greenhorn

Joined: May 17, 2003
Posts: 6
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

Joined: Aug 14, 2002
Posts: 279
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

Joined: Mar 05, 2003
Posts: 72
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

Joined: May 17, 2003
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml in JSP page
 
Similar Threads
html:img NullPointerException
class file is not loading while running JSP file
form not allowed in table tag?
Javascript Parameters --> Servlet
why doesn't request.getParameter( "j_username" ) work?