on 01-24-2007 7:50 AM
Dear All,
How do you decide which to use 'SAX or DOM' for java mapping?
Regards,
Ashish
Hi Ashish,
It depends on the Size of the XML Document that you are going to handle and the Memory constraints.
DOM Constarints:
1. DOM builds an in-memory tree of an entire document. If the document
is very large, this requires a significant amount of memory.
2.The DOM creates objects that represent everything in the original document,
including elements, text, attributes, and whitespace. If you only care about a
small portion of the original document, it's extremely wasteful to create all
those objects that will never be used.
3.A DOM parser has to read the entire document.For very large documents, this could cause a significant delay.
SAX Constraints:
1.SAX events are stateless. When the SAX parser finds text in an XML
document, it sends an event to your code. That event simply gives you the
text that was found; it does not tell you what element contains that text.
you want to know that, you have to write the state management code
yourself.
2. SAX events are not permanent. If your application needs a data structure
that models the XML document, you have to write that code yourself. If you
need to access data from a SAX event, and you didn't store that data in your
code, you have to parse the document again.
Above all these technical Details.
DOM is easier to code and maintain. It is difficult in case of SAX.
Regards,
Sudharshan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.