Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM API vs SAX API

 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you use these API's in real world scenarios, i know the difference between them theoretically just by reading books.

Any experienced guys out there shed some light?
 
Theodore Casser
Ranch Hand
Posts: 1902
Hibernate Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just depends on what you're trying to accomplish when you're parsing the XML (ie, are you searching it for specific nodes, or building something based on a single pass through the whole tree). You tailor your application to use one or the other given the requirements and resources.

DOM recreates the tree in memory and forces you to walk through it, step by step, to find what you want. SAX lets you look for specific nodes as you wander, but does it all in one pass. So that's usually the guide for determining, in the real world, which one to use.

Hope it helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic