Hi folks,
I am in a ANDROID project that use XPATH a lot. I followed the way in The Force Unleashed: XML+XPath On Android Using Dom4j And Jaxen. Everything's fine beside the performance. The XML file's big and read intensively. Following code consume 6 mins.
org.dom4j.Document MatrixXML = (new org.dom4j.io.SAXReader()).read(this.getResources().getAssets().open(XMLFile));
for (int i = 0; i < ListUsedQuestions.size(); i++) {
aQuestion = ListUsedQuestions.get(i);
List DxList = new ArrayList<Node>();
DxList = MatrixXML.selectNodes("/diagnoses/diagnosis[question[@id='" + aQuestion.getQuestionID() + "' and @weighting < 0]and not(@triggersystemid='" + systemID + "')]");
}
I think it is worth to try DOM since it store all XML file in the memory. I tried following code but the last line has a error:
org.w3c.dom.Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(this.getResources().getAssets().open(XMLFile));
DOMXPath xpath = new DOMXPath("/xpath.......");
List DxList = xpath.selectNodes((Node)doc.getDocumentElement()); <--- ERROR
Can anyone have any suggestion for me in this situation?
Thanks guys.