What are the differences between SAX and DOM parser
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. |
No comments:
Post a Comment