Android: Best parser to parse XML data [closed]
Asked Answered
S

4

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.

Sib answered 25/3, 2013 at 6:7 Comment(3)
use sax or xmlpullparsing.Chlorophyll
if the file size is reasonable, try dom. if it won't fit in core, use sax. show us your schema and tell us what kind of stuff you are doing with the dataSexpartite
Means sax if good then dom for heavy data but please tell me about xmlpullparser. The best among sax and xmlpull.Sib
C
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.

Choreodrama answered 25/3, 2013 at 6:24 Comment(1)
sorry but SAX parser has issue with self close tag <tag />, do you have any solution to solve that?Rondi
C
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.
Coverlet answered 25/3, 2013 at 6:10 Comment(1)
+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.Souvaine
C
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.

Choreodrama answered 25/3, 2013 at 6:24 Comment(1)
sorry but SAX parser has issue with self close tag <tag />, do you have any solution to solve that?Rondi
F
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

Felafel answered 25/3, 2013 at 6:14 Comment(0)
Q
0

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

Quantum answered 30/4, 2015 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.