How to fill data into xml format? - android

I have a huge amount of data (200 pages) and i need to import it to sqlite database through XML(in android)
i want to parse xml data and save it to db in android...
i want these data available from the first installing the app...
i want to know what is the easiest way to import data into XML format...
because data is too much lengthy i need some help from you to solve it easier...
what is the easiest way to achieve to suitable xml format
is there any software to handle this problem or should done manually???
how to put data in xml format ?

use simpleframework.
It is a java xml serialization/deserialization library which is pretty easy to use.
I used it in my last android app and it works really well.

Related

Load large amount of data to DB - Android

I'm building a new application to the Android platform and I need a suggestion.
I have a large amount of data that I want to import into a sqlite DB, something like 2000 rows.
My question is what is the best method to load the data into the DB?
Two ways I think of:
An xml file that holds all the data and then loads it with DocumentBuilder object.
A CSV file, and loads it with String Tokenizer. Found that post.
I want it to be with external file because When I release an update I will replace only the that file.
I want something that would be efficient as much as possible - all the data will load at the first startup of the application and I need it to be fast.
Any suggestion would be great.
Thanks.
Use InsertHelper to do a bulk insert.
Take a look on this other question
Instead of XML or CSV files, you can directly use an external sqlite DB you prepared in your computer. This technique is explained here: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
It really does not matter - you can achieve good perfomance with both approaches. With XML you can use some databinding, making programming easier (marginally). You may also consider JSON as transport format.
When parsing, keep in mind that building complete object tree in memory ( like XML DOM parser) consumes a lot of memory and results in a lot of allocations - pull parsing model like XPP / GSON is preferable.

Best way to update sqlite on Android

I would like some advice. I'm going to be using an sqlite database that will be pulling down information from my server and then saving it in the DB then displaying it. Could someone advise me of the best way to populate the DB, should I...
Use a http request and return a string de-liminated with say a | and use a loop to write to the data base.
Use a JSON to retrieve the information and then store it in the database.
The information is going to be just text and some fields will contains links to images I want to then download (get to that later). Just wanted some advice on best practices. I have done some searches on SO and other sites but can't find much advice. Also as a side note any examples you know of that are good for noobs :)
Based on what you write here I would pick JSON.
To core points:
JSON is a standard format.
Android ships with a JSON lib (org.json) making it easy to handle it (encode / decode data).
JSON is known by a large community so you can ask questions and get them answered rather easily. With a custom format you cannot tag the question as 'json' here at SO... ;-)
Using standard formats and libraries helps you to avoid designing and implementing this stuff yourself, which makes your software more robust.
Sometime later you might need to add more complex data to your project. By that time it will be rather straightforward to use JSON's array and objects. With your private scheme you will have to add this capability to it and extend your parsing code. That can easily introduce subtle bugs. Or you might decide at that point that it is too hard with your custom format and decide to move over to a standard like JSON, XML, etc. At that time it costs you much more to shift over than if you start with a standard format. Consider time invested to write and test the current code and then the extra time to change to the standard format for the current system.

Handling large XML files in Android

I'm new to Android development and want to create a Google map app. I have to use 2 large XML files with geo data (latlons), 1 is 2mb and the other 8 mb big.
What is the fastest way to access and parse this data? Is it maybe beter to store this into a database? A webservice is not a good idea I think, because everytime the app will start I have to load 10 mb... And that will process very slow I guess...
Has anybody some good advice?
Thanks!
Keep the whole data in the server and access it from device using webservices. Better to go for SAX parser as the data is too large. If possible better to implement search functionality from server end or to implement pagination from server end.
Maybe you can create some kind of meta data to go along with the large xml file. This meta data can point to specific parts of the large xml file. And each small part can be a dom object instead of a sax parser.
I suggest using sax, creating a summary of the data you need in some kind of hashtable (simple key value pairs) and using it. May be using SharedPreferences for data that does not change.
Also you need to think on how / what data will be used and how frequently. May be you can keep a producer consumer architecture, where a thread prepares the data for use, and the consumer uses it when its ready on a notify or something.
You need to think from 3 angles
Not too much serial processing
Not redoing what you have already parsed
Parsing using the right quantum of data. Infact think of dom for small parts to make your design easier to start with.
And I dont recommend DOM for the entire tree. You need to use a combination of SAX and DOM.
First get it working, and then record response/performance delays and work your way up to improve it from the worst to best.

What type of storage for some text in android?

I'm making a game to run on android. So I want to store player names and the winner, which I will also list up in a view. What is the best way to do this, use a database or write to a file (if so, what type, xml?). I have to be able to add data after every completed game, and the size won't be so large. What would be the best solution?
IMO, using a SQLite database would be the most straightforward. You don't have to worry about the xml parsing that goes along with an xml file. Additionally, the data your storing seems to have a natural relationship that would be conducive to a SQLite schema. For more information about how to use SQLite in Android, see the data storage documentation here.
SQLite is great if you have database concerns and want that sort of data lookup.
However, if you really want to do it Simply with XML then you can in Android.

SQLiteDatabase or XML(saving)?

Thanks for making android a wonderful platform.
What is the best option for saving a well formatted document(a document with images) on a device?
I know this can be done by saving to a XML file or on a database, but which of these two is the most preferable.
Thanks in advance.
-Ernest
Usually using XML or SQL database are differents approches for differents needings. Typically a database solution is more efficent than XML.
But XML has a tree structure that is easier to map in a object oriented language. I'll suggest you to use XML for the following reason:
easier to load data from xml to an object into your program
Easier to modify your page structure (with sql without a ORM system maybe difficult)
you are saving a "well formatted document" with images which has a naturally XML representation
You are on a mobile device and i don't think you need something like concurrently access to the same XML file or things like that
SQL would require installing a database, XML are just a standalone format

Categories

Resources