I was studying xmls to create dynamically changing db. I studied to different types of parsers which helped to retrive the information. But which parser to use..? I confused. It depends upon the application we prefere. I copied the difference between them here.
| SAX | DOM |
| 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. | |
| Parses node by node | Stores the entire XML document into memory before processing |
| Doesn’t store the XML in memory | Occupies more memory |
| We cant insert or delete a node | We can insert or delete nodes |
| Top to bottom traversing | Traverse in any direction. |
| SAX is an event based parser | DOM is a tree model parser |
| SAX is a Simple API for XML | Document Object Model (DOM) API |
| import javax.xml.parsers.*; import org.xml.sax.*; import org.xml.sax.helpers.*; |
import javax.xml.parsers.*; import org.w3c.dom.*; |
| doesn’t preserve comments | preserves comments |
| SAX generally runs a little faster than DOM | SAX generally runs a little faster than DOM |
| If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory. | |





