Both SAX and DOM are used to parse the XML document. Both
has advantages and disadvantages and can be used in our
programming depending on the situation
1. Parses node by node
2. Doesnt store the XML in memory
3. We cant insert or delete a node
4. Top to bottom traversing
1. Stores the entire XML document into memory before processing
2. Occupies more memory
3. We can insert or delete nodes
4. Traverse in any direction.
If we need to find a node and doesnt need to insert or
delete we can go with SAX itself otherwise DOM provided we
have more memory.
1. sax is an event based parser and raise and event, while
dom is not
2. sax is forward only where as dom can acess both was
forward as well as backwards.
3. sax parses the file as it reads where as the dom loads
the file into memory to parse the file.
4. Sax does not have memory constraints where as the dom
has momory constraints as xml file is loaded into the
momory to parse the file.
5. sax is read only , dom is read and write both.
6. if you have to parse and use the content only once ,
consider using sax if the xml file and content are used
extensively then consider using dom
It really nice Explanation by penchala the more about XML
SAX Parser is the one which is developed to run the java
DOM is developed by w3c consortium so that it is an open
In DOM the xml file is arranged as a tree and backward and
forward search is possible for searching the tags and
evaluating the data which it holds.
It depends upon the application and ease of data
If we want to extract the data from a xml file once we
have to move to SAX which is one time top to bottom read
approach and if we want ot randomly pick the data in an xml
file then the tree reperesentation of DOM model is to be
put into use. Thats all !
1. Tree of nodes
2. Memory: Occupies more memory, preffered for small XML
3. Slower at runtime
4. Stored as objects
5. Programmatically easy
6. Ease of navigation
1. Sequence of events
2. Doesn't use any memory preferred for large documents
3. Faster at runtime
4. Objects are to be created
5. Need to write code for creating objects
6. Backward navigation is not possible as it sequentially
processes the document
sax is simple api for xml
it read the first xml data and get outputed backward is not
dom is doccument object model
through dom we can create a xml data as a tree and it is
loaded in memory so we can easily access the data