0
我想在這個XML得到這個值B006PF20EI
與XPath的單值解析XML返回空字符串
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<OperationRequest>...</OperationRequest>
<Items>
<Request>...</Request>
<TotalResults>8</TotalResults>
<TotalPages>1</TotalPages>
<MoreSearchResultsUrl>...</MoreSearchResultsUrl>
<Item>
<ASIN>B006PF20EI</ASIN>
我使用XPath的,像這樣
public String parseXml(String xmlString){
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document dDoc = builder.parse(new InputSource(new StringReader(xmlString)));
XPath xPath = XPathFactory.newInstance().newXPath();
//Node node = (Node) xPath.evaluate("/Items/Item/ASIN", dDoc, XPathConstants.NODE);
//System.out.println(node.getNodeValue());
String value = xPath.evaluate("/ItemSearchResponse/resp/status", dDoc);
return value;
} catch (Exception e) {
Log.e("MYAPP", "exception", e);
return null;
}
}
但它看起來像該方法只是返回一個emptry字符串
對不起,已經很晚了。謝謝您的幫助。 –