You know , reading from memory and reading from disk , which one is faster. I think, everyone says memory will be faster. And you know Tree data structure is faster. So, DOM is inspired from inMemory loading and Tree datastructure.
Both the parser work in different way internally ,but intent of both are same. Internal implementation of DOM Vs SAX are different. It means, with same intent philosophy of the implementation are different.
1. Key Difference of DOM and SAX
- DOM stands for Document Object Model while SAX stands for Simple API for XML parsing.
- DOM parser load full XML file in memory and creates a tree representation of XML document, while SAX is an event based XML parser and doesn’t load whole XML document into memory.
- DOM parser load entire XML file in memory and creates a tree structure of XML document, while SAX is an event based XML parser and doesn’t load whole XML document into memory
- If you know you have sufficient amount of memory in your server you can choose DOM as this faster because load entire xml in memory and works as tree structure which is faster to access.
- As a thumb rule, for small and medium sized XML documents, DOM is much faster than SAX because of in memory agnostic.
2. DOM Vs SAX[table “” not found /]
Your comments are welcome. Happy Learning 🙂