6

I am developing an application in which the first time I am going to parse data from an xml file coming from a remote server.

But i am not able to select which parser is efficient or best suited for parsing. As there are mainly three types of parsing, which i know :

  1. SAX
  2. XMLPullParsing
  3. DOM

Which is the best parser to parse data? As I searched on Google and found the positive and negative both sides of the above parsers. But I was not able to determine which is the most efficient.

The XML has heavy data with a number of tags.

Please guide me and suggest me which parser I should use as I am using parsing in my application for first time.

David Manpearl
  • 12,362
  • 8
  • 55
  • 72
Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95

4 Answers4

18

SAX Parsing is the Best one to implement than DOM. See the difference between these two in the following:

DOM:

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

SAX:

  • Sequence of events.
  • It doesn't use any memory preferred for large documents.
  • Faster at runtime, because of the above mentioned point.
  • Objects are to be created.
  • Need to write code for creating objects.
  • In SAX Backward navigation is not possible as it sequentially processes the document.
David Manpearl
  • 12,362
  • 8
  • 55
  • 72
Prashant Shilimkar
  • 533
  • 1
  • 3
  • 10
  • 2
    +1. This is an excellent comparison. I would emphasize that SAX is more difficult to implement because you the programmer must step through the nodes. But, it is faster, uses less memory, and is far better suited to large XML data sets or streaming XML data. – David Manpearl Mar 25 '13 at 06:41
9

In all the XML parser's Sax parser is the fastest one so you can go for it with no doubt ....If you need to read and write the data from an XML you can go for DOM. Using the SAX parser you will be only be able to read the data from the XML. Since these two are in the top of the list you no need to think of the XMLPullparser.

Sreedev
  • 6,563
  • 5
  • 43
  • 66
1

I would say XMLPullParsing, but i have heard great things lately about Xerces might want to look into that one as well. However, never used Xerces and XMLPullParser has never failed me. We build a color blind app that used it and it pulls thousands of color combo's in order to tell you what color you just took a picture of.

update: heres a few links to read if you dont mind reading :p, shows cons and perks to both sides

http://www.firstobject.com/xml-reader-sax-vs-xml-pull-parser.htm

Also another answer to maybe read into SAX parser vs XMLPull parser

Community
  • 1
  • 1
NodeDad
  • 1,519
  • 2
  • 19
  • 48
0

I think the XMLPullParser would be a good option as they have mentioned in Android documentation.

denizen
  • 458
  • 1
  • 5
  • 15