Android: Best parser to parse XML data [closed]

人盡茶涼 提交于 2019-12-10 13:24:48

问题


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.


回答1:


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.




回答2:


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.



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/15608647/android-best-parser-to-parse-xml-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!