• 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

SAX Or DOM Which is efficient. my thoughts

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I havent worked much on XML, but I just wanted to clarify this question.
If the DOM creates a tree, and one is supposed to travesrse it for getting a specific node, then is it worth while using DOM for say some 15 -20 nodes?
I think it will traverse the tree each time a specific nod value is asked for.
So request for 20 nodes will traverse the tree 20 times.
in comparision, SAX will parse it sequentiually and we can extract the required data while parsing itself.
Doesnt this make SAX more effective when we have huge XML???
Please let me know if my thoughts are ambigiious
Thnx
Rajani
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it depends on what your doing with the parsed data. If you just need to process it once, say convert it to html, I'm guessing SAX would be more efficient. But if you need to parse the document and keep it in memory for random access, maybe it's better to leave it in the dom rather than map it to some other objects in memory. Unless you think that you can map the dom to your own objects that will be more efficient to access. You can do this but you probably want to weight that effort against your anticapated performance gains.
Thanks for reading.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DOM and SAX has their own pro's and cons depending on how they are used.
DOM is usefull when data/object represented in XML/XSL file is required for processing more than once. Down side is you can't load whole XML file in to DOM (memory) if XML file size is too large. http://65.1.136.127/developerlife/parsertest2/performance.html has performance statistics for reading XML files with varying sizes using different parsers.
SAX is usefull when you need to read data from XML file once, and either convert node data into objects or process immediatly and there is no need to go back to XML file for structural information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic