我想从以下 Web 服务中获取描述、供应商和价格。[链接] http://sagt.vizushop.com/DefaultSimple.aspx?command=item_price&id=11
回复如下
<item_details>
<description>
Jakl (Kumbuk) Center Table Timber : Mahogany/Rubber
</description>
<price>12600</price>
<vendor>BLUE</vendor>
</item_details>
我尝试使用以下示例,但它不起作用 - 为变量提供空值。
String vendor="";
String price="";
String description="";
try {
URL url = new URL("http://sagt.vizushop.com/DefaultSimple.aspx?command=item_price&id=11");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("description");
//description=nodeList.item(0).getNodeValue();
Node node = nodeList.item(0);
description = node.getNodeValue();
Log.v(TAG, description);
}