jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes SAX or DOM?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX or DOM??" Watch "SAX or DOM??" New topic
Author

SAX or DOM??

Nicolaas van Rensburg
Greenhorn

Joined: Jul 16, 2004
Posts: 8
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

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Ben Ethridge
Ranch Hand

Joined: Jul 28, 2003
Posts: 108
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

Joined: May 29, 2003
Posts: 1258
Poor salmon.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SAX or DOM??