Android Open Source - AndroidDev Android Sax 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;
//www . j av a  2  s  . c  om
import java.util.ArrayList;
import java.util.List;

import android.sax.Element;
import android.sax.EndElementListener;
import android.sax.EndTextElementListener;
import android.sax.RootElement;
import android.util.Xml;

public class AndroidSaxFeedParser extends BaseFeedParser {

  static final String RSS = "rss";
  public AndroidSaxFeedParser(String feedUrl) {
    super(feedUrl);
  }

  public List<Message> parse() {
    final Message currentMessage = new Message();
    RootElement root = new RootElement(RSS);
    final List<Message> messages = new ArrayList<Message>();
    Element channel = root.getChild(CHANNEL);
    Element item = channel.getChild(ITEM);
    item.setEndElementListener(new EndElementListener(){
      public void end() {
        messages.add(currentMessage.copy());
      }
    });
    item.getChild(TITLE).setEndTextElementListener(new EndTextElementListener(){
      public void end(String body) {
        currentMessage.setTitle(body);
      }
    });
    item.getChild(LINK).setEndTextElementListener(new EndTextElementListener(){
      public void end(String body) {
        currentMessage.setLink(body);
      }
    });
    item.getChild(DESCRIPTION).setEndTextElementListener(new EndTextElementListener(){
      public void end(String body) {
        currentMessage.setDescription(body);
      }
    });
    item.getChild(PUB_DATE).setEndTextElementListener(new EndTextElementListener(){
      public void end(String body) {
        currentMessage.setDate(body);
      }
    });
    try {
      Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
    } catch (Exception 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