Android Open Source - AndroidDev Xml Pull Feed Parser






From Project

Back to project page AndroidDev.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidDev listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.developerworks.android;
/* w  w w .  jav a2s .  co m*/
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Log;
import android.util.Xml;

public class XmlPullFeedParser extends BaseFeedParser {

  public XmlPullFeedParser(String feedUrl) {
    super(feedUrl);
  }

  public List<Message> parse() {
    List<Message> messages = null;
    XmlPullParser parser = Xml.newPullParser();
    try {
      // auto-detect the encoding from the stream
      parser.setInput(this.getInputStream(), null);
      int eventType = parser.getEventType();
      Message currentMessage = null;
      boolean done = false;
      while (eventType != XmlPullParser.END_DOCUMENT && !done){
        String name = null;
        switch (eventType){
          case XmlPullParser.START_DOCUMENT:
            messages = new ArrayList<Message>();
            break;
          case XmlPullParser.START_TAG:
            name = parser.getName();
            if (name.equalsIgnoreCase(ITEM)){
              currentMessage = new Message();
            } else if (currentMessage != null){
              if (name.equalsIgnoreCase(LINK)){
                currentMessage.setLink(parser.nextText());
              } else if (name.equalsIgnoreCase(DESCRIPTION)){
                currentMessage.setDescription(parser.nextText());
              } else if (name.equalsIgnoreCase(PUB_DATE)){
                currentMessage.setDate(parser.nextText());
              } else if (name.equalsIgnoreCase(TITLE)){
                currentMessage.setTitle(parser.nextText());
              }  
            }
            break;
          case XmlPullParser.END_TAG:
            name = parser.getName();
            if (name.equalsIgnoreCase(ITEM) && currentMessage != null){
              messages.add(currentMessage);
            } else if (name.equalsIgnoreCase(CHANNEL)){
              done = true;
            }
            break;
        }
        eventType = parser.next();
      }
    } catch (Exception e) {
      Log.e("AndroidNews::PullFeedParser", e.getMessage(), e);
      throw new RuntimeException(e);
    }
    return messages;
  }
}




Java Source Code List

nl.componentagro.feedparser.BaseFeedParser.java
nl.componentagro.feedparser.FeedParser.java
nl.componentagro.feedparser.ImageRef.java
nl.componentagro.feedparser.Message.java
nl.componentagro.feedparser.XmlPullFeedParser.java
nl.componentagro.kbreader.CAKennisbankLezerActivity.java
nl.rhoek.mygpspos.GPSPosActivity.java
nl.rhoek.mygpspos.GPSTracker.java
nl.rhoek.mygpspos.util.SystemUiHiderBase.java
nl.rhoek.mygpspos.util.SystemUiHiderHoneycomb.java
nl.rhoek.mygpspos.util.SystemUiHider.java
nl.ronaldhoek.helloandroid.HelloAndroid.java
org.developerworks.android.AndroidSaxFeedParser.java
org.developerworks.android.BaseFeedParser.java
org.developerworks.android.DomFeedParser.java
org.developerworks.android.FeedParserFactory.java
org.developerworks.android.FeedParser.java
org.developerworks.android.MessageList.java
org.developerworks.android.Message.java
org.developerworks.android.ParserType.java
org.developerworks.android.RssHandler.java
org.developerworks.android.SaxFeedParser.java
org.developerworks.android.XmlPullFeedParser.java