views:

117

answers:

1

All of the android examples for XmlPullParser pull from a local resource file, and all of the SAX examples pull the XML from a URL. I've been told SAX is faster, so I'm trying to use that to pull data from a local resource file (res/xml/thefile.xml)

The example code I'm working off of is here. So in that example, the code I want to change is:

URL url = new URL("http://example.com/example.xml");
...
xr.parse(new InputSource(url.openStream()));

Instead of using URL, I want to use getXml(R.xml.thefile) Is that possible, or does SAX need to get data from a URL?

+1  A: 

The SaxParser has a parse function that takes in a File handler. Additionally, there is one that takes an InputStream, so you should be able to use whatever datasource you like.

This article on working with XML might be useful to you. Its true that generally a SAX parser is faster for large datasets, however, it is also harder to work with, so you might want to way the size of your dataset against the complexity of the parser in deciding which type to use.

Mayra
You get a checkmark for the first part of your answer. But you get a smile for the second part. I'm using XMLPullParser, and things are moving right along. Thanks :-)
Bromide