Android REST XML result to Listview

2020-08-07 10:42发布

问题:

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.

回答1:

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)