Skip to content Skip to sidebar Skip to footer

Xmlpullparser How To Attain Res/raw/xml/xmlfilename?

I am new to programming, so to start with correct me if I am wrong in the paragragh below : There is mainly three xml parsers for use in Android : Sax, Dom, and XmlPullParser. Tha

Solution 1:

XmlPullParser is not really a parser, it is an interface to a type of parser, called a "pull" parser.

The function getResources().getXml() returns an implementation of XmlPullParser for "parsing" XML resources. This is not a real XML parser -- in fact the original XML file was parsed at build time before being built into your app, and what this "XML parser" is doing is just returning the pre-digested XML structure as you call its API. This is the fastest "XML" parser available on Android (because it is not really parsing anything), but requires that the XML document be compiled as part of building your app.

The other implementation of XmlPullParser that you get from XmlPullParserFactory.newInstance() is not "limited" -- this implementation is full-featured, and can parse any raw XML document you give to it.

At least at one time (not sure if this is still the case), both the SAX parser and the parser returned by XmlPullParserFactory.newInstance() are actually built on the same underlying implementation, which is expat. The expat parser is a "push" parser (that is the same model as SAX), so the most efficient way to use it is with the SAX API. The XmlPullParser version has some more overhead from SAX since it needs to turn the underlying push semantics into a pull interface.

If it helps -- push means that it pushes the parsed data to you (callbacks you implement giving you each tag and other document element), while pull means you make calls to the parser to retrieve each element.

Post a Comment for "Xmlpullparser How To Attain Res/raw/xml/xmlfilename?"