Baran Topal

Baran Topal


May 2024
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


SAX vs. DOM parsing

baranbaran

I will come with examples for both of them. For聽starters, following is the general theory. Some information from stackoverflow 馃檪

SAX Parser:

路 聽 聽 聽 聽A SAX (Simple API for XML) parser does not create any internal structure. Instead, it takes the occurrences of components of an input document as events, and tells the client what it reads as it reads through the input document.

路 聽 聽 聽 聽A SAX parser serves the client application always only with pieces of the document at any given time.

路 聽 聽 聽 聽A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). What鈥檚 more, it runs faster and is easier to learn than DOM parser because its API is really simple. But from the functionality point of view, it provides a fewer functions, which means that the users themselves have to take care of more, such as creating their own data structures.

DOM Parser:

路 聽 聽 聽 聽A DOM (Document Object Model) parser creates a tree structure in memory from an input document and then waits for requests from client.

路 聽 聽 聽 聽A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.

路 聽 聽 聽 聽A DOM parser is rich in functionality. It creates a DOM tree in memory and allows you to access any part of the document repeatedly and allows you to modify the DOM tree. But it is space inefficient when the document is huge, and it takes a little bit longer to learn how to work with it.
Here are some very interesting links

http://allu.wordpress.com/2006/12/28/difference-between-sax-and-dom-parsers/
http://www.cs.nmsu.edu/~epontell/courses/XML/material/xmlparsers.html
http://www.devx.com/xml/Article/16922/1954