title: parsing XML String having same tag name using XmlPullParser in Android
body: <pre><code>&lt;ArrayOfArtist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"&gt;
  &lt;Artist&gt;
  &lt;place&gt;1&lt;/place&gt;
  &lt;Albums&gt;
  &lt;Album&gt;
  &lt;SongNames&gt;
  &lt;string&gt;foo&lt;/string&gt;
  &lt;string&gt;bar&lt;/string&gt;
  &lt;string&gt;baz&lt;/string&gt;
   &lt;/SongNames&gt;
   &lt;/Album&gt;
   &lt;/Albums&gt;
   &lt;Name&gt;Mr Guy&lt;/Name&gt;
   &lt;/Artist&gt;
   &lt;Artist&gt;
   &lt;place&gt;2&lt;/place&gt;
   &lt;Albums&gt;
   &lt;Album&gt;
   &lt;SongNames&gt;
   &lt;string&gt;green&lt;/string&gt;
  &lt;string&gt;orange&lt;/string&gt;
  &lt;string&gt;red&lt;/string&gt;
   &lt;/SongNames&gt;
   &lt;/Album&gt;
   &lt;/Albums&gt;
   &lt;Name&gt;Mr Buddy&lt;/Name&gt;
   &lt;/Artist&gt;
   &lt;Artist&gt;
   &lt;place&gt;3&lt;/place&gt;
   &lt;Albums&gt;
   &lt;Album&gt;
   &lt;SongNames&gt;
   &lt;string&gt;brown&lt;/string&gt;
   &lt;string&gt;pink&lt;/string&gt;
   &lt;string&gt;blue&lt;/string&gt;
   &lt;/SongNames&gt;
   &lt;/Album&gt;
   &lt;Album&gt;
   &lt;SongNames&gt;
   &lt;string&gt;apple&lt;/string&gt;
   &lt;string&gt;orange&lt;/string&gt;
   &lt;string&gt;pear&lt;/string&gt;
   &lt;/SongNames&gt;
   &lt;/Album&gt;
   &lt;/Albums&gt;
   &lt;Name&gt;Mr Friend&lt;/Name&gt;
   &lt;/Artist&gt;
   &lt;/ArrayOfArtist&gt;                    
  </code></pre>
  
  <p>what i need is to parse the XML above and print the place,name and the song names for each artist.</p>
  
  <p>the problem is that for each artist i am only getting the last song name</p>
  
  <p>this is what i tried. Album is a class having String name and place and Songname. </p>
  
  <pre><code>                ArrayList&lt;Album&gt; products = null;   
                  Album a=null;
                   while(xpp.getEventType() !=XmlPullParser.END_DOCUMENT){
                       String name=null;
                       switch (xpp.getEventType()){
                       case XmlPullParser.START_DOCUMENT:
                          products = new ArrayList();
                           break;
                       case XmlPullParser.START_TAG:
                           name = xpp.getName();
                           Log.e(TAG,"name is"+xpp.getName());
                           if (xpp.getName().equals("ArrayOfArtist")){
                               Log.e(TAG,"herehere");
                               a = new Album();
                           } else if (a != null){
                               if (name.equals("Artist")){
                                   Log.e(TAG,"artart");
                                   }
                               if (name.equals("place")){
                                   Log.e(TAG,"placeplace");
                                  a.place = xpp.nextText();
                               }
                               else if (name.equals("Name")){
                                   Log.e(TAG,"namename");
                                   a.name = xpp.nextText();
                               }
                              else if (name.equals("string")){
                                           Log.e(TAG,"songssongs");
                                           a.seSongs(xpp.nextText());
                                       }  
                           }
                           break;
  
                       case XmlPullParser.END_TAG:
                           name = xpp.getName();
                           if (name.equalsIgnoreCase("ArrayOfArtist") &amp;&amp; a != null){
  
                               products.add(a);
                           } 
               } 
                       xpp.next();
                   }
                   printProducts(products);
          }
          catch (Exception e){
  
          }
  
     }
  }
  private void printProducts(ArrayList&lt;Album&gt; products)
  {
      String content = "";
      Iterator&lt;Album&gt; it = products.iterator();
      while(it.hasNext())
      {
          Log.e(TAG,"hete");
          Album currProduct  = it.next();
          content = content + "name :" +  currProduct.name + "\n";
          content = content + "place :" +  currProduct.place + "\n";
          content = content + "Songnames :" +  currProduct.Songname + "\n";
  
      }
  
      TextRecieved.setText("content is: "+content);
  }
  </code></pre>