Question:
What is the difference between DOM and SAX? What would you use if an option is given?
Answer:
DOM 1. Tree of nodes 2. Memory: Occupies more memory, preffered for small XML documents 3. Slower at runtime 4. Stored as objects 5. Programmatically easy 6. Ease of navigation SAX 1. Sequence of events 2. Doesn't use any memory preferred for large documents 3. Faster at runtime 4. Objects are to be created 5. Need to write code for creating objects 6. Backward navigation is not possible as it sequentially processes the document Source: CoolInterview.com
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. Source: CoolInterview.com
Answered by: venkatareddy | Date: 3/10/2016
| Contact venkatareddy
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|