Android App Development: Parsing Web Service response

In the last post we saw how to call REST and SOAP web services. The web service reponse can be one of the following:

  1. XML.
  2. SOAP.
  3. JSON.

Parsing XML

Android offers three types of XML parsers:

  1. DOM Parser.
  2. Pull Parser.
  3. SAX Parser.

we’ll demonstrate each using the following xml example:

<?xml version="1.0"?>
<person>
    <firstname>Jack</firstname>
    <lastname>smith</lastname>
    <age>28</age>
</person>

which we need to parse to create an object from Person class:

public class Person{
    	public String firstName;
    	public String lastName;
    	public int age;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *