0

Sorry, this seems like such an obvious question, but I just can't find an answer in the docs...

I have my own XML doc (not Android related) that I need to pull and parse at run time.

Where do I store it and what's the best way to retrieve it? Do I just read it as a text document into an XML parser? Or does Android come prepared to hand me back a parsed XML object from a well formed xml?

TIA

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

3 Answers3

3

You can put it in assets folder of your project.

For parsing you can use openXmlResourceParser(filename) method of AssetsManager class

XmlResourceParser parser = getResources().getAssets().openXmlResourceParser (String fileName);
Ron
  • 24,175
  • 8
  • 56
  • 97
  • check this tutorial for accessing files from `raw` and `assets` folders : http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders – Ron Oct 11 '11 at 17:29
3

Put it in a xml folder in res.

user
  • 86,916
  • 18
  • 197
  • 190
  • 1
    @Dr.Dredel you should be able to access your file with `R.xml.file_name` (http://developer.android.com/reference/android/R.xml.html) – user Oct 11 '11 at 17:33
2

Best way is to put your xml in assets folder and read xml from assets.

Read xml from assets

Community
  • 1
  • 1
Dharmendra
  • 33,296
  • 22
  • 86
  • 129