Reputation: 4408
I have an xml where the parent and child node has same name . The xml is
<response>
<cmd>abcr</cmd>
<success>1</success>
<response>
<user_login>....</user_login>
<user_email>..</user_email>
</response>
<errCode>0</errCode>
<errText/>
</response>
ie i have a response within response . I need to extract the value of userlogin
i have code
doc = parser.getDomElement(xml);
NodeList responseList = doc.getElementsByTagName("response");
Element response = (Element) responseList.item(0);
String name = parser.getValue(response, "user_login");
It is not working correctly . What should i change to make it correct. please help
Upvotes: 0
Views: 283
Reputation: 11
Answered my own question...
xmlMessagesCount = xml.documentElement.getElementsByTagName("messages").item(0).getChildNodes().length;
Upvotes: 0
Reputation: 1495
Try Below code:
NodeList nodeList = doc.getElementsByTagName("user_login");
String name = nodeList.item(0).getChildNodes().item(0).getNodeValue();
Upvotes: 1