DOM & SAX parsers

Explain about DOM & SAX parsers with real-time example of usage

Questions by sudhakar_bvr   answers by sudhakar_bvr

Showing Answers 1 - 5 of 5 Answers

Eshwar

  • Jun 6th, 2006
 

DOM is Document Object Model. The entire XML document is loaded into the memory and is stored in the tree structure. So we can have easy traversal. In the case of large xml documents better to use SAX, coz the entire document is loaded into the memory which is memory consuming.

SAX is Simple API for XML parsing, it is event driven, means for every tag an event is fired like start tag, end tag etc. The document is not loaded into the memory as DOM. you have to handle the events (which most programmers try to esacape :)

Thanks and Regards

Eshwar

Subhash Thakur

  • Aug 10th, 2006
 

Nice Eshwar,thats true :-) but personally i feel SAX makes many good advantages over DOM when it comes to reading and have a custom validation on XML documents. Isn't it ?regards,Subhash

  Was this answer useful?  Yes

Chandan Reddy

  • May 16th, 2007
 

DOM:
-Its Object Driven parser
-Creates copy of XML document in Tree format, good for Large sized XMLs but very memory consuming for Large sized XMLs (think about XMLs which has 2GB or more size)
-Moves Backward&Forward directions in XML document
-supports CRUD
-bit slower compared to SAX

SAX:
-Its Event Driven parser
-Uses existing XML document...so doesn't create new one
-Moves Forward ONLY
-Doesn't support CRUD
-Recommended for large scale XML data transfers and where memory is costly.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions