【问题标题】:How to extract a value of a http xml answer using android java如何使用android java提取http xml答案的值
【发布时间】:2013-05-15 06:06:49
【问题描述】:

好吧,我对 android 有点陌生,我正在尝试获取 http 答案的价值。但我以前从未使用过那些 XML 的东西。

网络服务示例:http://freegeoip.net/xml/123.123.123.123

这是这里的结果

<Response>
<Ip>123.123.123.123</Ip>
<CountryCode>CN</CountryCode>
<CountryName>China</CountryName>
<RegionCode>22</RegionCode>
<RegionName>Beijing</RegionName>
<City>Beijing</City>
<ZipCode/>
<Latitude>39.9289</Latitude>
<Longitude>116.388</Longitude>
<MetroCode/>
</Response>

如何获取countrycode、regioncode等的值...

【问题讨论】:

  • 搜索XPath,应该对你有帮助。
  • @Maroun Maroun 举个例子

标签: java android xml


【解决方案1】:

您应该使用 SAX API (Simple Api for XML) 解析来自 web 服务的 xml 并使用 DefalutHandler 类处理它。这是 DefaultHandler 类的文档:http://developer.android.com/reference/org/xml/sax/helpers/DefaultHandler.html 这是一个从 0 开始的不错的教程,它应该可以帮助你:http://www.codeproject.com/Articles/334859/Parsing-XML-in-Android-with-SAX

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-30
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    相关资源
    最近更新 更多