title: How to parse xml response in android?
body: <p>In my application i am receiving the below Httpresponse from a webservice in xml format.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;results&gt;
  &lt;result&gt;
  &lt;status&gt;0&lt;/status&gt;
  &lt;messageid&gt;213123&lt;/messageid&gt;
  &lt;destination&gt;1234567890&lt;/destination&gt;
  &lt;/result&gt;
  &lt;/results&gt;
  </code></pre>
  
  <p>I tried parsing the response in the below format : </p>
  
  <pre><code>    private void parseXML(XmlPullParser parser) throws XmlPullParserException,IOException
  {
      ArrayList&lt;SMSResponse&gt; products = null;
      int eventType = parser.getEventType();
      SMSResponse currentProduct = null;
  
      while (eventType != XmlPullParser.END_DOCUMENT){
          Log.e("ENTER-", "while loop");
          String name = null;
          switch (eventType){
              case XmlPullParser.START_DOCUMENT:
                  products = new ArrayList&lt;SMSResponse&gt;();
                  Log.e("ENTER-", "swicth case -1");
                  break;
              case XmlPullParser.START_TAG:
  
                  name = parser.getName();
                  Log.e("start name", name);
                  if(name.equals("results"))
                  {
                       Log.e("start name", name);
                  }
                  else if(name.equals("result"))
                  {
                       Log.e("start name", name);
                      currentProduct = new SMSResponse();
                  }
                  else if(name.equals("status"))
                  {
                       Log.e("start name", name);
                       System.out.println("status value==");
                      currentProduct.status = parser.getProperty(name).toString();
  
                  }
                  else if(name.equals("messageid"))
                  {
                       Log.e("start name", name);
                       System.out.println("messageid value=="+ parser.getProperty(name));
                      currentProduct.messageid = parser.getProperty(name).toString();
                  }
                  else if(name.equals("destination"))
                  {
                       Log.e("start name", name);
                       System.out.println("destination value=="+ parser.getProperty(name));
                      currentProduct.destination = parser.getProperty(name).toString();
                  }
  
                  break;
              case XmlPullParser.END_TAG:
                  name = parser.getName();
                  Log.e("end name", name);
  //                    Log.e("ENTER-", "switch case-3");
                  if (name.equalsIgnoreCase("results") ){
                       Log.e("end name", name);
                      products.add(currentProduct);
                  } 
          }
          eventType = parser.next();
      }
  
  
      Log.e("Array", products.toString());
  
  //        printProducts(products);
  }
  </code></pre>
  
  <p>But i am getting null response as the value. </p>
  
  <p>How do i extract the value of the xml header? </p>
  
  <p>Please Help ! Thanks in Advance!</p>