KCTechNet
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.
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.
ASKER
I had actually run across this one. But like the posted comments said, the article was not really that useful.
>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
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
ASKER
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...
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Just get the two jars for JSTL.
But if you are going to use XPath then you will need the Xalan jar.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
ASKER
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.
ASKER
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.
If you want more help on your hypothetical, please create adequate test files and post them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-jspxml.html