簡體   English   中英

來自Android中URL的Xml值

[英]Xml values from URL in android

下面的xml文件位於“ 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>

我想獲取abc名稱的第一,第二,第三,第四和最后一個值。 我如何從xml URL獲取值?

您應該嘗試使用DOM解析器。 您應該嘗試使用DOM解析器。

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           
         }

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM