Newbie question: how to look for a particular element in an XML document?

S

Sunitha Kumar

Hi,

I'm just learning SAX, so I would appreciate advice with this problem I'm
wrestling with.

Here's the scenario:
I've just parsed a xml document and stored the values I need in a class so I
can print it out. But, I'm also looking for a particular data element within
the elements, so I pass in the value I'm looking for, via the command line
arguments.

For example, within the element <year>, I'm looking for the value 1988.

Should I:
1. create another handler just to handle this case?
(maybe subclass the class extending the DefaultHandler and override the
endElement method?)

2. I tried this approach, which failed miserably (it printed out everything
anyway)
if (year.equals(yearToFind))
{
System.out.print(article.toString);
}
else {
//print out what I have without worrying about a particular year
System.out.println(article.toString);
}

How can I do this? Any suggestions, comments, advice would be welcome!

Thanks,
Sunitha Kumar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top