|
If your document is really large, or you only need to extract a few elements from the whole document, then using DOM is not practical.
SAX Looks for startElement events in which the element name is verse, then looks at each character event for the name
SAX is more efficient because we only care about a few elements in the document
SAX is good when:
You only need to go through a document once
You’re only looking for a few items
You’re not too concerned with document structure of the context of the elements you’re looking for
You don’t have much memory
DOM Builds Java objects for everything in the document, then walks through the tree looking for the name. Using DOM, we create a lot of Java objects we never use, and we go through the document twice (once to parse it and once to search it)
DOM is good when:
- You need to go through a document more than once
You need to manipulate lots of things
in the document The structure of the document and the
context of the elements is a concern
Memory is not an issue
|