Android: writing to xml -


i have xml called weatherdata.xml (which resides in eclipse's >assets< folder) , looks like

<?xml version="1.0" encoding="utf-8"?> <weather> <weatherdata>     <id>1</id>     <city>berlin</city>     <tempc>0°c</tempc>     <tempf>32°f</tempf>     <condition>snowing</condition>     <windspeed>5 kmph</windspeed>     <icon>snowing</icon> </weatherdata>     <weatherdata>     <id>5</id>     <city>sydney</city>     <tempc>32°c</tempc>     <tempf>89.6°f</tempf>     <condition>sunny</condition>     <windspeed>10 kmph</windspeed>     <icon>sunny</icon> </weatherdata> 

so trying add 1 more city, @ runtime .. tried java alone , working fine this

i thought work fine android, android functions altogether differently desktop application couldn't go further

and found this interesting, (though not appending)

so question is

  • what sdcard, need write it

  • so if im writing sdcard can expect same output on emulator aswell on actual device

  • if yes,will path- /sdcard/weatherdata.xml

apart that, there rights(manifest.xml) bothering me write xml file

assets read-only files packaged part of apk. cannot change them.

you have 2 places can write files application:

  1. sd-card (or "external storage")
  2. private data area application on phone's internal memory

these bit different , have different set of advantages/disadvantages, follows:

  1. sd-card:

    • files write on sd-card not deleted when app uninstalled
    • you need read_external_storage , write_external_storage permissions access files on sd-card
    • some devices don't have sd-card support or user may not have installed sd-card in slot
    • the user can remove/replace/format sd-card in case files write there lost
    • user can read/write files on sd-card connecting device pc or removing sd-card , mounting on pc
  2. private data area:

    • files write here deleted when app uninstalled
    • user cannot read or write these files (unless phone rooted)
    • you don't need permissions read/write in private data area

i suggest copy xml file assets private data area (if isn't there) , use copy private data area. if want add entries it, update copy in private data area.

to open file in private data area, use openfileinput() , openfileoutput(). behaviour same on emulator on device.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -