Advertisement

03.24.2008 at 07:29PM PDT, ID: 23265949
[x]
Attachment Details

Java SAX programming question

Asked by fsyed in JAXP & SAX (XML APIs), Java Programming Language, Extensible Markup Language (XML)

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("Current day: " + today.get(Calendar.DAY_OF_MONTH));
               System.out.println("Current month: " + getMonthName(today));
               System.out.println("Current 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;
FayyazStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<calendar>
	<month name="January">
		<date day="1">
			
				<A>Text A</A>
				<B>Text B</B>
				<C>Text C</C>
				<D>Text D</D>
				<E>Text E</E>
				<F>Text F</F>
			
		</date>
		<date day="2">
			
				<A>Text A</A>
				<B>Text B</B>
				<C>Text C</C>
				<D>Text D</D>
				<E>Text E</E>
				<F>Text F</F>
			
		</date>
                  ...
      </month>
      ...
</calendar>
 
Keywords: Java SAX programming question
 
Loading Advertisement...
 
[+][-]03.24.2008 at 08:56PM PDT, ID: 21199398

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JAXP & SAX (XML APIs), Java Programming Language, Extensible Markup Language (XML)
Sign Up Now!
Solution Provided By: cmalakar
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.26.2008 at 06:40AM PDT, ID: 21211442

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 06:46AM PDT, ID: 21211524

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.02.2008 at 07:41PM PDT, ID: 21269380

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 11:48AM PDT, ID: 21275646

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628