DOM Parser:-
The
Document Object Model (DOM) is a platform and
language-independent standard object model for representing XML and related
formats. DOM is standard API which is not specific to any programming language.
DOM represents an XML document as a tree model. The tree model makes the XML
document hierarchal by nature. Each and every construct of the XML document is
represented as a node in the tree.
SAX Parser:-
SAX-Simple
API for XML processing. SAX provides a mechanism for reading data from an XML
document. It is a popular alternative to the Document Object Model (DOM).SAX
provides an event based processing approach unlike DOM which is tree based.
Difference between SAX
parser and DOM parser:-
SAX
|
DOM
|
A
SAX parser takes the occurrences of components of an input document as events
(i.e., event based processing), and tells the client what it reads as it
reads through the input document.
|
A
DOM parser creates a tree structure in memory from an input document and then
waits for requests from client.
|
No
navigation possible (top to bottom only once)
|
Whereas,
we can navigate the DOM tree in any direction, any no. of times.
|
We
cannot modify the document content in SAX
|
We
can modify the document content in DOM
|
A
SAX parser serves the client application always only with pieces of the
document at any given time.
|
A
DOM parser always serves the client application with the entire document no
matter how much is actually needed by the client.
|
A
SAX parser, however, is much more space efficient in case of a big input
document
|
A
DOM parser is space inefficient when the document is huge.
|
Use SAX parser
when
|
Use DOM when
|



0 comments:
Post a Comment