0

I am developing an android app and in that I want to use a XML file. I think its a kinda web services and i want to use it in my app. so first of all i am thinking that whenever I open my app it fetch the whole XML file from http://data.gov.in/sites/default/files/Date-Wise-Prices-all-Commodity.xml and save it into assets folder of my App and then after I will use this XML from my assets folder.

I know this stuff is not too much difficult but actually i am new to android that's why getting this type of problem.

Please help.

Thanks in Advance.

Shiv
  • 129
  • 1
  • 9

2 Answers2

0

You can't. The assets folder is read-only at runtime.

Pick a different location to save your data, see Data Storage for more information.

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • So, please tell me what could I do for this work ? or where should I save this XML so further i can use it in my app – Shiv Oct 17 '13 at 06:58
  • You can save it in sdcard. See example http://stackoverflow.com/questions/8986376/how-to-download-xml-file-from-server-and-save-it-in-sd-card – Madhur Ahuja Oct 17 '13 at 07:04
  • And then after can I use this XML for my App. Actually this XML contain some data that I want to use in my app. – Shiv Oct 17 '13 at 07:09
0

As posted in other answer you have to choose different location. Rest method is as following.

  • Make a method or class to make http request.

  • Get response from given request.

  • Make a xml parser (DOM Parser,Pull Parser or SAX)

these are the basic steps. hope it will help.

Check this tutorial

Sandeep
  • 2,573
  • 3
  • 21
  • 28
  • Can I have an simple example of these basic steps please ? – Shiv Oct 17 '13 at 07:05
  • is is necessary to store xml? you can parse direct from http response – Sandeep Oct 17 '13 at 07:12
  • I am trying to store this becoz if sometime the user don't have Internet on their phone then they don't get any error. The data from the Local XML that is fetched previously can be shown to user. This is what I want. – Shiv Oct 17 '13 at 07:18
  • ok then first download xml from server save it to sdcard. Then you can parse. – Sandeep Oct 17 '13 at 07:19
  • The example you have given is it for the same or for the direct usage ? – Shiv Oct 17 '13 at 07:22
  • read this tutorial it will help you to download xml on sdcard. http://www.androidhive.info/2012/04/android-downloading-file-by-showing-progress-bar/ – Sandeep Oct 17 '13 at 07:23
  • you have you read and make all required component at your own. No body can give the complete code as per you requirement. – Sandeep Oct 17 '13 at 07:25
  • Let me check and please stay in touch so that I can take help from you on this topic. – Shiv Oct 17 '13 at 07:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39402/discussion-between-deepsan-and-shiv) – Sandeep Oct 17 '13 at 07:31