I need to save a xml file from sdcard to my android app, in res/values. How can I do this? Can anyone help me?
just use the java file command for your xml file on sdcard.
File file=new File("/mnt/sdcard/example.xml");
and using DOM or SAX parser you can parse the data(information) from it for your application.
Thnx.
EDIT: parsing local xml file using Sax in android, Read XML Resources in Android, using XmlResourceParser: XML parsing interface or Here or Here Look at these tutorials.
They are just folders in an Android project when you develop. When the app is compiled, everything in src and res is turned into binary code, and packed in one apk. Therefore I don't think that you will have res folder or anything like that in the device.
Related
I have an xml file (contains images) in the file. The file size is about 50M.
When i read it in flex
on iOS it read well, no problems. Everything is ok
but on Android always it gives me error #1085.
The file and code are the same in Android and iOS.
The XML file is valid - I have tested it on XML validator.
Can anyone tell me what to do?
Check the encoding of the file... it might be that the file is saved with a different encoding on android.
I have an application where at one stage, I need to download the latest xml file from a server and store it in internal storage (data/data/packagename/filename.xml). I've searched online and its not possible to save file at runtime to res folder, so I have to use internal storage.
However, I'm struggling to try and parse the xml file. Previously I've been using the XmlResourceParser to parse static xml already stored in res/xml/ folder. It's very easy to use. So I'm wondering if theres a way to use XmlResourceParser to parse the newly downloaded xml file. Otherwise, how should I parse the xml file?
Thanks.
XmlResourceParser is for binary xml files in res folder only. But you can use XmlPullParser. It can read data from an InputStream.
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
Store it in the cache directory.
getCacheDir();
so you can say filename = getCacheDir() + file123.xml;
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
I am new to Android. I've created a .csv file in SD card. Now I want to open this file but unable to do this.
Please help me on how to open a .csv file.
You can open a .csv file like you would any text file. In order to read it, look for some examples in java - like Parse CSV File using StringTokenizer example
http://code.google.com/p/secrets-for-android/source/browse/trunk/src/au/com/bytecode/opencsv/CSVReader.java?r=19
This could parse a csv file
I posted some example code here: How to parse the CSV file in android application?
You would obviously have to change it slightly to access a file on the sdcard and not in the assets folder.
I have two XML files located in res/xml/. One file is a normal XML file located in that directory called myfile.xml and I can access it normally as R.xml.myfile.
Eclipse allows you to link files in from other locations. I have another XML file that is linked in from another drive. No matter what I do, i can not access this file by R.xml.newfile. I've even tried a DTD file, and isn't available via R either.
Am I doing something wrong, or is this some kind of bug?
No matter what I do, i can not access
this file by R.xml.newfile. I've even
tried a DTD file, and isn't available
via R either.
If the "linked" file is not in your res/ directory tree, aapt will not find it. If you can get Eclipse to set up "linked" files as symlinks in Linux/OS X, it might work. Or, you can skip the Eclipse "linked" concept and set up the symlink yourself. Or, you can create your own build script to copy the file from its existing spot to your project's res/ directory.
Well if the file is not in res or assest folders or inside your project how would it be available when the application is going to execute on actual device.
If the requirements remain same try accessing the xml file generated by another program as a network resource
use SAX Parser to regain the XML data, i dont know about DTD, but i prefer to use SAX or DOM to access a XML file. Sorry cant paste the code here since the SAX uses lot of classes, so tell me whether you need it or not