cancel
Showing results for 
Search instead for 
Did you mean: 

SAX and DOM

Former Member
0 Kudos

Dear All,

How do you decide which to use 'SAX or DOM' for java mapping?

Regards,

Ashish

View Entire Topic
Former Member
0 Kudos

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