Extracting values in XML file to JSP

Hey,

Currently I have a drop down menu with several date ranges in them. These are hard coded and I wish to make it easier to change in the future or even add new ones.

<select name="leaveYr">

<option value="1">1st Febuary to 31st January</option>

<option value="2">1st April to 31st March</option>

<option value="4">1st May to 30th April</option>

</select>

Now I want to use a XML file which can hold these values and populate them from XML File. Problem is I have never used XML files, so im unsure how to go about this.

I know for some of you this will be a stupid question and tell me to google it. I am doing this but not making much sense at the moment. If any of you could give a few clues, example to go about it that would be great.

Regards

Steven

[971 byte] By [Lunnya] at [2007-10-3 4:39:50]
# 1

[url=http://java.sun.com/xml/tutorial_intro.html]The Java/XML Tutorial[/url].

From the sounds of it, you want to run XSLT over a the XML file.

But if you have never used XML before, maybe reading some tutorials/getting a book out on it first would be good.

[url=http://www.w3schools.com/xml/]XML tutorial[/url]

[url=http://www.w3schools.com/xsl/]XSLT Tutorial[/url]

mlka at 2007-7-14 22:43:46 > top of Java-index,Java Essentials,Java Programming...
# 2
Have you considered using the the JSTL core tags relating to XML? http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL5.html#wp63716
jennyFromTheBronxa at 2007-7-14 22:43:46 > top of Java-index,Java Essentials,Java Programming...
# 3

For such a simple set XML is probably overkill, a simple text file with one string per line would probably do you.

However, for small amount of simple XML, you're best bet is probably to use XPath. You'll need to study the JavaDocs (javax.xml.XPath). Basically if will give you a NodeList of elements which you can iterate through.

However it's more efficient if you read the XML once and build an array the first time you run the JSP. Personally I wouldn't put stuff like this in a JSP itself, but create a separeate utility class which the JSP could reference, probably a singleton or a custom tag. The less complex java code in a JSP the better.

Get the XML file using getResourceAsStream on the servlet's context object, so you can put the XML in the WEB-INF directory of the web application.

malcolmmca at 2007-7-14 22:43:46 > top of Java-index,Java Essentials,Java Programming...