Reputation: 2613
I have read the tutorial from ibm about xml parsing
(http://www.ibm.com/developerworks/opensource/library/x-android/)
In this example,there are four types of xml parsing.Dom,Sax,Android Sax and xml_pull.Could you please tell me what's the difference between these four types and when i have to use each one?
Also,with every way of xml parsing in this tutorial,the feeds are shown in a listView. What i have to do in order to appear every announcement in a btn for example?
thanks for your time!Merry Christmas:D
Upvotes: 4
Views: 6488
Reputation: 25760
DOM (Document Object Model) parsing is similar to using DOM in Javascript to represent the document as a tree of nodes. It is convenient to use, but is also the slowest way to parse XML documents.
SAX on the other hand is the fastest way to parse XML documents on Android (source). It involves specifying a handler class that implements certain methods that are called as the document is parsed. It's a bit cumbersome to use but I recommend it for large documents or if XML parsing is proving to be a performance bottleneck.
Android provides some helper classes to make using SAX easier. Basically instead of defining a class you can just register separate event handlers for the events you care about. It's still using the SAX parser behind the scenes.
The pull parser allows you to pull events in a loop and handle the ones you care about. In my opinion it's easier to use than the SAX parser but is a little slower. It should be fast enough for most applications.
Upvotes: 5