• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Searching using SAX !!

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I'm building context specific help for a project that i'm working on & The complete Help related data is stored in an XML file which is of the following format.


The task is to write a Java Program that has a method that takes a help ID & returns the Help-Topic & Help-Data associated with it.

I believe SAX would be the write thing to use as the file is expected to be very large & i am aware of the events that a SAX Parser generates. Here's the skeleton code that i plan to use.


Please suggest the right way to search for the Help-Topic & Help-Data for a given ID.
 
Marshal
Posts: 28260
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

Is SAX ideal to use is this case ?
 
Paul Clapham
Marshal
Posts: 28260
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic