Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load and Query large xml file Android

I’m building an android app and I have a xml file which is my data source, I load it to make queries using XPath and then load the results in a ListView. The problem comes out when the xml file start to become bigger(up to 10MB). It means that i could have problems with memory, i guess. I would like to know what’s the best way to load the xml and make searchs into the file without compromise the device’s memory or waste valuable time processing data.

Here is when i load the xml file:

InputStream isRaw = context.getResources().openRawResource(R.raw.xmlbooksource);
_xmlBookSource = new InputSource(isRaw);

And here i make a query using XPath:

nodeResultSet = (NodeList) xpath.evaluate(xpathExpression, _xmlBookSource, XPathConstants.NODESET);

all advices are welcome.

like image 377
AXSM Avatar asked Apr 21 '26 22:04

AXSM


1 Answers

While they can be used as a data source and can be searched using XPath; XML are not really made for these purposes and should be limited to the transfert of data between systems.

If your data source is anything but very small, you should seriously think about using a database like SQLite for storing and querying your data.

like image 122
SylvainL Avatar answered Apr 24 '26 12:04

SylvainL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!