Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml vs. sqlite for android and how to

I have several xml files with schemas, some of them quite large (around 16MB in total) with a lot of interdependencies. I want to make use of this data within my android app. The data will be searched frequently but very rarely changed.

  1. Should I keep them as xml files or should I convert the data to an sqlite db? Which one is faster? Is memory space a problem with 16MB on android device?

  2. If it's better to convert the xml files to sqlite db, how do I go about doing this? I saw this thread:

How to convert xml to sqlite database in android platform?

which from my understanding, suggest streaming the xml file into db, but it only talks about one xml file. With several xml files representing objects with dependencies, what extra work do I have to do, for example, do I have to do some sort of binding first? If so, what tool is best for the task?

I'm very new to android dev and sqlite so any suggestion would be very appreciated.

like image 812
nullgraph Avatar asked Nov 06 '22 01:11

nullgraph


1 Answers

Take a look at this answer:

Raw resources versus SQLite database

With regards to this question...

How to convert xml to sqlite database in android platform?

... I think it makes no sense to serialize an XML... it will make things too much slower: you will have to deserialize and then parse the XML. So, the best you can do is putting all your data inside an XML table.

As the data will not change, you can create the database outside the device. I mean, create the database on your desktop, then put the database in the assets folder of your android app and copy it to the device.

How you put the XML in the database? It depends on the structure of the XML files... create tables according to the info you have in the XML, including all relations (which you can emulate using foreign keys, etc...). What I would do is creating an script or something to do that work (it could be a Java app, a perl script, a python program, or whatever you feel comfortable with).

like image 126
Cristian Avatar answered Nov 10 '22 20:11

Cristian