aspose file tools*
The moose likes XML and Related Technologies and the fly likes Difference between SAX and DOM parsers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Difference between SAX and DOM parsers" Watch "Difference between SAX and DOM parsers" New topic
Author

Difference between SAX and DOM parsers

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hello folks,
Can anyone let me know what is the difference between SAX and the DOM parsers??

I hope to get some comments on this.

Saurabh


Success is not doing extraordinary things but doing ordinary things extraordinarily well.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
SAX is an event-based API, which means that a SAX parser generates events when making its way through an XML document.

DOM, on the other hand, is a tree-based API, which means that a DOM parser creates a DOM tree out of the elements it encounters while making its way through an XML document.

I'd recommend looking up articles named "Understanding SAX" and "Understanding DOM" at IBM developerWorks.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Also SAX is for sequential access and DOM for random access. DOM requires more memory in case of big xml file.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between SAX and DOM parsers