0

在此示例中,如何在 Android 上的 Java 中获取用户 ID 值?

<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]
4

1 回答 1

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);
于 2013-11-04T10:39:29.957 回答