title: How to parse an RSS feed with XmlPullParser?
body: <p>I would like to parse a RSS feed. My question is how I can parse all tags between the <code>&lt;item&gt;</code>and <code>&lt;/item&gt;</code> tags. </p>
  
  <p>Given this very simple XML:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;rss version="2.0"&gt;
  &lt;channel&gt;
    &lt;title&gt;MyRSSPage&lt;/title&gt;
    &lt;link&gt;http://www.example.com&lt;/link&gt;
    &lt;item&gt;
    &lt;link&gt;www.example.com/example1&lt;/link&gt;
    &lt;title&gt;Example title 1&lt;/title&gt;
    &lt;/item&gt;
    &lt;item&gt;
    &lt;link&gt;www.example.com/example2&lt;/link&gt;
    &lt;title&gt;Example title 2&lt;/title&gt;
    &lt;/item&gt;
  &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>I would like to parse just the stuff between the <code>&lt;item&gt;...&lt;/item&gt;</code> tags.</p>
  
  <pre><code>            List&lt;RssMessage&gt; messages = new ArrayList&lt;RssMessage&gt;();
  
              // parser is a XmlPullParser instance
              while(parser.next() != XmlPullParser.END_DOCUMENT) {
                  if (parser.getEventType() != XmlPullParser.START_TAG) {
                      continue;
                  }
              String name = parser.getName();
              // START OF HEADER
              if(name.equals("title")) {
                  title = parser.nextText();
              }
              else if(name.equals("link")) {
                  link = parser.nextText();
              }
              else if(name.equals("description")) {
                  description = parser.nextText();
              }
              else if(name.equals("language")) {
                  language = parser.nextText();
              }
              else if(name.equals("copyright")) {
                  copyright = parser.nextText();
              }
              else if(name.equals("pubDate")) {
                  pubdate = parser.nextText();
              }
              // END OF HEADER
  
              else if(name.equals("item")) {
                  RssMessage rssMessage = processItem(parser);
                  messages.add(rssMessage);
              }
          }
  </code></pre>
  
  <p>In the below method I would like to just parse the tags within the <code>&lt;item&gt;...&lt;/item&gt;</code>tags. How do I construct a loop that just goes through the item between <code>&lt;item&gt;</code> and <code>&lt;/item&gt;</code>? </p>
  
  <p><strong>EDIT <br /></strong>
  This is almost working. But sometimes not all elements are initiated even if the corresponding element in the RSS xml DO exist! Is something wrong with the below code?</p>
  
  <pre><code>private RssMessage processItem(XmlPullParser parser) throws IOException, XmlPullParserException {
          RssMessage rssMessage = new RssMessage();
      parser.require(XmlPullParser.START_TAG, ns, "item");
      while (parser.next() != XmlPullParser.END_TAG) {
          if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
          String name = parser.getName();
          if(name.equals("link")) {
              rssMessage.setLink(parser.nextText());
          }
          else if(name.equals("guid")) {
              rssMessage.setGuid(parser.nextText());
          }
          else if(name.equals("category")) {
              rssMessage.setCategory(parser.nextText());
          }
          else if(name.equals("title")) {
              rssMessage.setTitle(parser.nextText());
          }
          else if(name.equals("pubDate")) {
              rssMessage.setPubDate(parser.nextText());
          }
      }
      return rssMessage;
      }
  </code></pre>