【问题标题】:android xml parsing nodes with same nameandroid xml解析具有相同名称的节点
【发布时间】:2013-09-17 08:09:11
【问题描述】:

我有一个父节点和子节点具有相同名称的 xml。 xml是

<response>
<cmd>abcr</cmd>
<success>1</success>
<response>
<user_login>....</user_login>
<user_email>..</user_email>
    </response>
<errCode>0</errCode>
<errText/>
</response>

即我在 response 中有一个 response 。 我需要提取 userlogin 的值

我有代码

doc = parser.getDomElement(xml);
            NodeList responseList = doc.getElementsByTagName("response");
            Element response = (Element) responseList.item(0);
            String name = parser.getValue(response, "user_login");

它不能正常工作。我应该改变什么以使其正确。 请帮忙

【问题讨论】:

  • 您需要获取并维护标志值。

标签: android xml xml-parsing


【解决方案1】:

试试下面的代码:

NodeList nodeList = doc.getElementsByTagName("user_login");
String name = nodeList.item(0).getChildNodes().item(0).getNodeValue();

【讨论】:

    【解决方案2】:

    回答了我自己的问题...

    xmlMessagesCount = xml.documentElement.getElementsByTagName("messages").item(0).getChildNodes().length;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-27
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多