[英]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
}
}
}
这些链接提供了一些示例和详细信息:
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
希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.