Dear Fellow Java/XML developers:
My question is this:
I have an XML file that looks like the attached code. I would like to write a java program that parses through this xml file and presents the elements, along with their respective values for the current date, as determined by the date on the user's PC. The code to determine the month and the day I already have figured out and is listed as an FYI (year is not necessary):
import java.util.Calendar;
public class Sample {
public static void main(String[] args)
{
Calendar today = Calendar.getInstance();
System.out.println("Curren
t day: " + today.get(Calendar.DAY_OF_
MONTH));
System.out.println("Curren
t month: " + getMonthName(today));
System.out.println("Curren
t year: " + today.get(Calendar.YEAR));
}
public static String getMonthName(Calendar today)
{
String month = "January";
switch(today.get(Calendar.
MONTH))
{
case Calendar.JANUARY: month = "January"; break;
case Calendar.FEBRUARY: month = "February"; break;
// Add cases for the remaining months...
}
return month;
}
}
Once the current month and day is determined, I want the program to then parse through the xml file and first find a match for the current month, and then find a match for the current day which would be it's child tag. Once both matches have been made, I would like to have the elements and their respective values presented to the user as follows:
Monday, January 1, 2008:
A. Text A
B. Text B
C. Text C
D. Text D
E. Text E
F. Text F
I believe SAX would be the preferred method of choice for this project, but am not sure how to begin. Any help would be greatly appreciated.
Thanks to everyone who replies.
Sincerely;
Fayyaz
Start Free Trial