Android REST XML 结果到 Listview [英] Android REST XML result to Listview

查看:24
本文介绍了Android REST XML 结果到 Listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 REST Web 服务,它返回如下 xml 结果:

I have a REST web service that returns an xml result like this:

- <MyCategories xmlns="http://schemas.datacontract.org/2004/07/ceva" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <Category>
  <CategoryName>First category</CategoryName> 
  <Id>1</Id> 
  </Category>
- <Category>
  <CategoryName>Second category</CategoryName> 
  <Id>2</Id> 
  </Category>
- <Category>
  <CategoryName>Third category</CategoryName> 
  <Id>3</Id> 
  </Category>
  </MyCategories>

我这样访问网络服务:

     HttpClient httpclient = new DefaultHttpClient();  
     HttpGet request = new HttpGet(WebServiceURL);  
     request.addHeader("deviceId", deviceId);  
     BasicResponseHandler handler = new BasicResponseHandler();  

     result = httpclient.execute(request, handler);

结果我从 Web 服务获得了 xml 响应.我希望能够使用此结果并将其显示在列表视图中.

In result I get the xml response from the web service. I want to be able to use this result and display it in a listview.

我怎样才能做到这一点?谢谢.

How can I achieve this ? Thank you.

推荐答案

您将要创建一个自定义 SAXParser 类.

You're going to want to create a custom SAXParser class.

这是一个不错的小教程

还有 docs(他们没有解释不过这很好)

And the docs (they don't explain this that well though)

这篇关于Android REST XML 结果到 Listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆