2011-03-31 41 views
0

我想執行的XPath查詢NODESET不能在Android的

我加入

import javax.xml.xpath.*; 

解析爲一個類型,我用這個代碼

XPath xpath = XPathFactory.newInstance().newXPath(); 
String expression = "/books/book"; 
InputSource inputSource = new InputSource("books.xml"); 
NodeSet nodes =(NodeSet) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); 

我用this文檔

但顯示錯誤NodeSet cannot be resolved to a type

預先感謝您

更新

我chaged代碼:

XPathFactory xPathFactory = XPathFactory.newInstance(); 
    // To get an instance of the XPathFactory object itself. 
    XPath xPath = xPathFactory.newXPath(); 
    // Create an instance of XPath from the factory class. 
    String expression = "/books/book"; 
    XPathExpression xPathExpression = xPath.compile(expression); 

    // Compile the expression to get a XPathExpression object. 
    Object result = xPathExpression.evaluate(R.raw.books); 
    //Evaluate the expression against the XML Document to get the result. 

但在這行

XPathExpression xPathExpression = xPath.compile(expression); 
    Object result = xPathExpression.evaluate(R.raw.books); 

xPath.compile(expression);xPathExpression.evaluate(R.raw.books);埃羅顯示錯誤rs

我現在在做什麼?

回答

0

根據this documentation NodeSet的java表示形式爲NodeList。您可以嘗試用NodeList替換NodeSet

NodeList nodes =(NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); 
+0

xpath.evaluate(expression,inputSource,XPathConstants.NODESET)中的錯誤; – User616263 2011-03-31 13:44:59