2

I would like to know what exact advantage is gained in doing Android XML Parsing using DOM Parser and SAX Parser?
Is it like DOm parser is advantageous than SAX Parser or vice-versa?

Please clarify.

Thanks,
Sen

Navaneeth Sen
  • 6,315
  • 11
  • 53
  • 82

1 Answers1

8

Hi SAX Parsing is the Best one to implement than DOM, see the difference between these two in the following:

DOM

  1. The Nodes are in the form of Tree Structure
  2. Memory: It Occupies more memory, DOM is only preffered in the case of small XML documents
  3. Slower at runtime
  4. Stored as an objects
  5. Programmatically easy to implement
  6. Ease of navigation and use.

SAX

  1. Sequence of events
  2. It doesn't use any memory preferred for large documents.
  3. Faster at runtime, because of the above mentioned point.
  4. Objects are to be created.
  5. Need to write code for creating objects
  6. In SAX Backward navigation is not possible as it sequentially processes the document
Community
  • 1
  • 1
Sankar Ganesh PMP
  • 11,927
  • 11
  • 57
  • 90
  • So if i plan to parse xml, are you suggesting like i should go for SAX Parser? – Navaneeth Sen Dec 21 '10 at 14:32
  • @Sen: Absolutely, you are right, you can use SAX Parser in the case of Parsing Large Document, it's has better performance rather than DOM, as i mentioned in the answer, Suppose if you are going to parse a small document, then you can use DOM parser. – Sankar Ganesh PMP Dec 21 '10 at 14:34
  • It is like, my xml will contain the path to many images located in a server PC. I want to download them and display it via Gallery. So i will parse this xml file and display the images on my screen. So for this scenario, could you suggest which is the best approach? – Navaneeth Sen Dec 21 '10 at 14:39
  • 1
    @Sen: The Best Approach for this scenario, is using SAX parser, because, in my experience i had implemented DOM parser initially to parse some images and show it in a list,it's very slow, and parsing took more time , so that, i had implemented the Same one in SAX, i felt the difference in Parsing the same one, so i would like to suggest you to use SAX Parser........ – Sankar Ganesh PMP Dec 21 '10 at 14:45