简体   繁体   中英

Xml values from URL in android

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           
         }

    }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM