Link to home
Start Free TrialLog in
Avatar of KCTechNet
KCTechNetFlag for United States of America

asked on

JSP with XML 'back end'

I need to find out if it is possible to have a jsp page that can use an XML document as if it was a database back end.  The project would be like a phone directory which I want the user to be able to filter the list by department, last name, first name, etc. with the data coming from an xml document.

Being COMPLETELY new to java/javascript I am having trouble even googling to find examples of how or if it can be done.

Any suggestions, sample code, links to websites would be GREATLY appreceiated.
Avatar of afibarra
afibarra
Flag of Mexico image

Avatar of KCTechNet

ASKER

I had actually run across this one.  But like the posted comments said, the article was not really that useful.
Avatar of rrz
>use an XML document as if it was a database back end.  
Will this be  read-only  ?  
If yes, then you could use JSTL and XPath  .  Are you familiar with them ?  
http://java.sun.com/javaee/5/docs/tutorial/doc/bnakq.html
http://today.java.net/article/2003/11/25/practical-jstl-part-2
yes, it woulld be read only
I will check out these links.  I just stumbled upon Xquery during some searches.  Not sure how Xquery and Xpath are different...
>Not sure how Xquery and Xpath are different...
http://www.ibm.com/developerworks/xml/library/x-xqueryxpath.html   

In order to use JSTL and its XML tags, you will have to download and install some extra jars.  Look at  
https://www.experts-exchange.com/questions/23412352/How-to-get-data-from-a-xml-file-in-a-jsp.html   
SOLUTION
Avatar of afibarra
afibarra
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you decide to try JSTL and you are using  Java 6, then you probably don't  need the Xalan jar.
Just get the two jars for JSTL.
But if you are going to use XPath then you will need the  Xalan jar.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mrcoffee has made some good points. But, if you use  JSTL  then things are much easier.  For example if you have an XML file that lists some student data then you could use something like the following code.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import var="studentsXml" url="students.xml"/>
<x:parse xml="${studentsXml}" var="myClass" />
The first student listed is
<x:out select="$myClass//name" />  
The names of all the students in the class are
<x:forEach var="student" select="$myClass//student" >
             <x:out select="name"/>
</x:forEach>

Open in new window

looking at the last code I see how to parse and retrieve all records.  but how do you query for a specific name?
Please show us a sample of your xml file.
The xml file has not been created yet.  I wanted to make sure this method would be possible before moving forward.  Basically it would be like a directory of companies with some the 'normal' fields, such as city, state, zip.  
Well we gave you hypothetical advice.

If you want more help on your hypothetical, please create adequate test files and post them.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rrz, awesome link.  thanks.

I will go ahead and close this question as everyone has given great advice.  I'm sure I will be posting more questions as I  proceed on the project.