CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES XML DETAILS
Question :
What are the differences between SAX and DOM parsers?



Category XML Interview Questions
Rating (0.0) By 0 users
Added on 7/19/2006
Views 1170
Rate it!
Answers:

Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation

SAX:

1. Parses node by node

2. Doesnt store the XML in memory

3. We cant insert or delete a node

4. Top to bottom traversing

DOM

1. Stores the entire XML document into memory before processing

2. Occupies more memory

3. We can insert or delete nodes

4. Traverse in any direction.

If we need to find a node and doesnt need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.



DOM Loads whole document into memory.So it requires lot of memory.
Not recommended for large XML Document.Using DOM you can traverse thru an XML document.
To parse XML in .NET enviornment using Document object model,use XmlDocument and XmlElement. These classes are available in System.Xml namespace

Using this classes,we can traverse an XML document and add,modify its element.

Creating XmlDocument
XmlDocument newXmlDoc = new XmlDocument();
Load Xml Document
newXmlDoc.Load(XmlFileName);
To Create Element
XmlElement newXmlElement = newXmlDoc.CreateElement("NEWELEMENT");
XmlElement newXmlMain = newXmlDoc.CreateElement("MAIN");
To Add Child
newXmlMain.AppendChild (newXmlElement);
Save Document
newXmlDoc.Save();



2.Simple API for XML (SAX)

Load/Read portion of XML document as needed.This is the best option when memory is limited.Cannot traverse backward thru an XML file.Speed is very less compare to DOM





 Posted by: Ruchi    

Contact Ruchi  Contact Ruchi


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What parser would you use for searching a huge XML file?

View Answer
When a XML file has a DTD declared which is not accessible to the parser, what would happen?

View Answer
How can u create an XML file?

View Answer
Other than XML/XSLT, what are other web services.

View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL XML Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6167/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

1.16