• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

SAX Or DOM Which is efficient. my thoughts

Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • 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.
Posts: 4
  • Mark post as helpful
  • send pies
  • 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. 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!