jsw
jsw

Reputation: 728

Store and Parse XML from the internet

I'm trying to find the best way to store XML files from the internet, so that i can parse them at a later date. I have no problems with downloading an xml file, and storing it in the

/data/data/package_name/files

folder. However i'm not sure how to read this file after it has been saved there, and to pass that read file to an instance of a SAX Parser. Additionally, i have noticed that it is quite slow to read the file from the phone, which is a concern.

I have read the storing XML files in the res/xml folder is a lot quicker - but i'm not sure if it's possible to save a file from the internet into this folder at runtime?

Any help would be appreciated :)

Cheeers

Upvotes: 1

Views: 482

Answers (2)

Hades
Hades

Reputation: 3936

Store it in the cache directory.

getCacheDir();

so you can say filename = getCacheDir() + file123.xml;

Upvotes: 2

fleetway76
fleetway76

Reputation: 1640

You cant write to the res folder at all. These resources are compiled into your app at build time and are read only. As for reading the file, You should just be able to create an input stream for it in the standard java way and parse out the bytes using your sax parser.

This section of the guide describes how to access the internal and external filesystems and how to get input/output streams. http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Upvotes: 2

Related Questions