In your startElement method, if the element name is Help-Item and the ID attribute contains the value you are looking for, set a boolean flag "helpItem" to true. If the element name is Help-Item and the ID attribute is something else, set it to false. If the element name is anything else, leave it alone.
Also in your startElement method, if the element name is Help-Topic, set a boolean flag "helpTopic" to true. If not, set it to false.
And in your startElement method, create an empty StringBuffer.
In your characters method, append the characters to the StringBuffer.
Finally in your endElement method, if helpItem is true and helpTopic is true, then the StringBuffer contains the help topic. Similar logic gives you the help data.
I hope you are not planning to do this search while an on-line user is waiting for you to display its results. If the XML file is large enough that you can't use DOM, it is going to take an annoyingly long time to do the search.
Joined: Oct 19, 2005
Thanks a lot Paul, Looks like i've got the answer...
No, this is for a desktop application. This is how it is actually supposed to work : for certain actions that a user performs with the GUI there is a help ID associated with it... So that the context specific help is displayed for what the user is doing now....!!
for example : if the user clicks on the "SEND MESSAGE" button help regarding sending a message is displayed in a panel.
I opted for SAX as i learnt from other posts in this forum that DOM is slower if the file is too large...
DOM may be slower if you re-parse the entire file every time you need some data from it. But why would you do that? The more sensible thing would be to parse the file once, at the beginning of the program, and build a Map that maps help-item-id to something containing help-topic and help-data. You could do this either in SAX or DOM, it wouldn't make much difference.
An even more sensible thing would be to not use XML at all for this application. If you just want help-item-id to be the key for finding help-topic and help-data then something which permits random access to the data would be preferable. Like a database.