繁体   English   中英

Android XML解析器值

[英]Android XML parser value

<current>
<city id="1839071" name="Hoko">
<coord lon="129.34" lat="36.01"/>
<country>KR</country>
<sun rise="2014-12-24T22:31:10" set="2014-12-25T08:14:18"/>
</city>
**<temperature value="3.964" min="3.964" max="3.964" unit="celsius"/>**
<humidity value="100" unit="%"/>
<pressure value="1031.09" unit="hPa"/>
<wind>
<speed value="9.71" name="Fresh Breeze"/>
<direction value="307.001" code="NW" name="Northwest"/>
</wind>
<clouds value="0" name="clear sky"/>
<visibility/>
<precipitation mode="no"/>
<weather number="800" value="Sky is Clear" icon="01d"/>
<lastupdate value="2014-12-25T07:46:40"/>
</current>

我想获得这部分的价值。

**<temperature value="3.964" min="3.964" max="3.964" unit="celsius"/>**

Weather_temperature = parser.getAttributeValue(null, "value");

那是对的吗?

如果文档较小,则可以加载文档并使用xpath定位temperature节点并到达value属性:

XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.evaluate("/current/temperature", parser, XPathConstants.NODESET);
String temperatureValue = nodes.item(0).getAttribute("value");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM