Below, xml file at " http://example.com/example.xml "
<xml>
<result>
<name>abc name</name>
<first>568</first>
<second>458</second>
<third>185</third>
<forth>236</forth>
<last>974</last>
</result>
<result>
<name>def name</name>
<first>214</first>
<second>456</second>
<third>457</third>
<forth>754</forth>
<last>746</last>
</result>
</xml>
i want get first, second, third, forth and last value for abc name. how i get values from xml URL?
You should try using DOM parser. You should try using DOM parser.
NodeList nList = doc.getElementsByTagName(“result”);
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
if( eElement.getElementsByTagName("firstname").item(0).getTextContent().equals(“abc”))
{
System.out.println(“first” + eElement.getElementsByTagName(“first”).item(0).getTextContent());
System.out.println(“second” + eElement.getElementsByTagName("nickname").item(0).getTextContent());
//And so on
}
}
}
These links provide some example and detail:
http://www.sitepoint.com/learning-to-parse-xml-data-in-your-android-app/ http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser http://www.ibm.com/developerworks/opensource/library/x-android/ http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
I hope this help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.