Android REST XML 结果到 Listview
我有一个 REST Web 服务,它返回如下所示的 xml 结果:
- <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>
我像这样访问 Web 服务:
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(WebServiceURL);
request.addHeader("deviceId", deviceId);
BasicResponseHandler handler = new BasicResponseHandler();
result = httpclient.execute(request, handler);
结果我从 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>
I acces the web service like this:
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(WebServiceURL);
request.addHeader("deviceId", deviceId);
BasicResponseHandler handler = new BasicResponseHandler();
result = httpclient.execute(request, handler);
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要创建一个自定义 SAXParser 类。
这是一个很好的小教程
和docs (不过他们没有很好地解释这一点)
You're going to want to create a custom SAXParser class.
Here's a nice little tutorial
And the docs (they don't explain this that well though)