在此示例中如何在Android上获取Java中的userid值?
<RESPONSE>
<SINGLE>
<KEY name="sitename"></KEY>
<KEY name="username"></KEY>
<KEY name="firstname"></KEY>
<KEY name="lastname"></KEY>
<KEY name="fullname"></KEY>
<KEY name="lang"></KEY>
<KEY name="userid"></KEY>
<KEY name="siteurl"></KEY>
<KEY name="userpictureurl"></KEY>
<KEY name="functions"></KEY>
<KEY name="downloadfiles"></KEY>
<KEY name="release"></KEY>
<KEY name="version"></KEY>
<KEY name="mobilecssurl"></KEY>
</SINGLE>
</RESPONSE>
需要输出
[userid value]
答案 0 :(得分:0)
使用SAX,您可以获得节点值:
String xPathExpression = "RESPONSE/SINGLE/KEY[@name= 'userid']/text()";
XPath path = XPathFactory.newInstance().newXPath();
String result = (String) path.evaluate(xPathExpression, new InputSource(new FileReader("..path to xml file..")), XPathConstants.STRING);