lundi 5 janvier 2015

XML to SQLite FTS Transformation

I imported data from 10 XML files to SQLite FTS Virtual Table. The Approach I adopted is Parsed XML documents using XML DOM Parser using object model. Then using a for loop I inserted data from corresponding object to SQLite Database.


The problem is it is tooo slow and takes a lot of time! I tried beginTransaction() and endTransaction() before and after for loop but it didn't helped.



DataBaseHelper mDbHelper = new DataBaseHelper();
XMLDOMParser parser = new XMLDOMParser();
AssetManager manager = getAssets();
InputStream stream1,...,stream10;

stream1 = manager.open("file1.xml");
stream2 = manager.open("file2.xml");
.......................................;
stream10 = manager.open("file10.xml");

Document document1 = parser.getDocument(stream1);
.....................................................;
Document document10 = parser.getDocument(stream10);

NodeList nodeList1 = documentl.getElementsByTagName(NODE_NAME);
...............................................................;
NodeList nodeList10 = documentl0.getElementsByTagName(NODE_NAME);
mDbHelper.open();
for (int j = 0; j < nodeList.getLength(); j++)
{
Object object = new Object();

Element e1 = (Element) nodeList1.item(j);
........................................;
Element e10 = (Element) nodeList10.item(j);

object.setValue1(e1.getAttribute(NODE_ATTRIBUTE));
.................................................;
object.setValue10(e10.getAttribute(NODE_ATTRIBUTE));

mDbHelper.insertData(object.getValue1,...,getValue10);
}
mDbHelper.close();

Aucun commentaire:

Enregistrer un commentaire