나는 100KB
에 대해 내 XML-file
에 대한 질문에 XPath
을 사용하고 있습니다.안드로이드 - XPath 매우 느림
나는 목록의 모든 값에 대해 배열과 쿼리를 반복하고있다.
불행히도 단일 쿼리는 디버거에서 약 3-4 초 ()가 소요되며 디버거는 사용하지 않는 경우 약간 적습니다.
왜 이렇게 느린가요? 테스트를 위해 Galaxy S2
을 사용합니다. 나는 XPathConstants.NODESET
evalution이 시간에 이루어집니다하지만 난 NodeList
을하지 않습니다을 떠날 때
XPath xpath = XPathFactory.newInstance().newXPath();
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.parse(new File(file_on_internal_sd_url)));
int size = mPrefs.getInt("no_ids", 0);
for(int i=0;i<size;i++) {
String id= mPrefs.getString("id_" + i, null);
String expression = "/tag1/tag2[@id = '" + id+ "']";
NodeList nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
if(nodes.getLength()>0) {
myElements.add((Element)nodes.item(0));
}
}
업데이트
:
여기 내 코드입니다. 대신 빈 문자열을 반환합니다 ...
함께 그 루프에서 3-4 MS 또는 모든 사람을 복용 _single_ 쿼리가 ? 귀하의 문서는 어떻게 생겼습니까? –
하나의 쿼리에는 약 3-4 초가 걸립니다 (!). 내 문서에는 하나의 루트 노드와 많은 자식 노드가 있습니다. 손자도 없어. – Ron
Ronvcan이 질문에 vtd-xml 태그를 추가 했습니까? –