I receive 360K of data from a server which I transform into a XML file on my phone. The final file is about 1.3 Mb. Later, I try to read this file and on my GT-S5660 and this process runs for 5(!) hours. Although it produces a correct result I wonder if there is a way to optimize this process. I have an iphone version of it, and there the process completes in less than 5 seconds.
Is this a normal behaviour? If so, would SQLIte be an alternative?
Here’s my code:
FileInputStream fileos;
try {
fileos = openFileInput("TarifsCache" + Constants.VERSION + ".txt");
} catch (FileNotFoundException e) {
return;
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
return;
}
Document doc;
try {
doc = db.parse(new InputSource(fileos));
} catch (SAXException e) {
return;
} catch (IOException e) {
return;
}
doc.getDocumentElement().normalize();
for (int i = 0;; i++) {
NodeList nodeList = doc.getElementsByTagName("Cache" + i);
Node node = nodeList.item(0);
if (node == null)
break;
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("area_ref");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
tarifread.area_ref = Integer.parseInt(((Node) nameList.item(0))
.getNodeValue());
followed by plenty of other element retrievals.
Try to use advance parser parser like SAX and dnt use STAX as its not support in android .