• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAX or DOM??

 
Nicolaas van Rensburg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone

I am currently busy with a Web Application using servlets and XML. The XML files I use will mainly be machine generated code. I am using my XML files mainly as a means of user profiling.

After reading many websites that claim DOM as the way to go with parsers and just as many which claim SAX as the only way to go, I am confused.


Which of these two parsers is the best one,? What are the main differences?, and Which parser is supported best in the JAVA API?

Any help and advice will be appreciated.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is best depends on what you're trying to do. As for what the differences are, I'll let you go out and do a little research. Both parser types are well supported by the Java API.
 
Ben Ethridge
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An analogy might be fishing on a bridge in a running river, where the river is the XML:

For SAX, the fisherman is going to stand on the bridge and has decided that she/he is only going to catch salmon, i.e. let all other species of fish go on by. So, for this fisherman, the SAX parser catches only the "salmon" elements as they go by.

For DOM, the fisherman is going to run a giant net across the river, and catch every fish in the river.

That's why it's sometimes said DOM is "heavier" than SAX. :-)

Might be a somewhat silly analogy, but helps me remember the difference.

Ben
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poor salmon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic