简单的rss阅读器

时间:2016-07-23 06:54:39
【文件属性】:

文件名称:简单的rss阅读器

文件大小:372KB

文件格式:RAR

更新时间:2016-07-23 06:54:39

xml解析

这是一款简单的rss阅读器,用xml解析 package com.fenghuo.xml; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.http.entity.InputStreamEntity; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import com.fenghuo.model.RssItem; public class ParseRssSAX { public static List parseRss(InputStream is, String encode) { try { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); InputSource in = new InputSource(new InputStreamReader(is, encode)) ; RssParserHandler handler = new RssParserHandler(); parser.parse(in, handler) ; return handler.getData(); } catch (ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (SAXException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } class RssParserHandler extends DefaultHandler{ private Listdata; public RssParserHandler(){ this.data=new ArrayList(); title=link=pubDate=description=""; } public ListgetData(){ return data; } private String title,link,pubDate,description; private boolean isTitle = false , isLink = false , isPubDate = false , isDest = false; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // TODO Auto-generated method stub if(localName.equalsIgnoreCase("title")){ isTitle=true; } else if(localName.equalsIgnoreCase("link")) { isLink = true; } else if(localName.equalsIgnoreCase("pubDate")) { isPubDate = true; } else if(localName.equalsIgnoreCase("description")) { isDest = true; } else if(localName.equalsIgnoreCase("item")) { title = link = pubDate = description = ""; } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { // TODO Auto-generated method stub if(localName.equalsIgnoreCase("title")) { isTitle = false; } else if(localName.equalsIgnoreCase("link")) { isLink = false; } else if(localName.equalsIgnoreCase("pubDate")) { isPubDate = false; } else if(localName.equalsIgnoreCase("description")) { isDest = false; } else if(localName.equalsIgnoreCase("item")) { RssItem item = new RssItem(title, link, pubDate, description); // Log.e("sax,item" , item.toString()); data.add(item); } } @Override public void characters(char[] ch, int start, int length) throws SAXException { // TODO Auto-generated method stub String text=new String(ch,start,length); text=text.trim(); if(isTitle){ title+=text; }else if(isLink){ link+=text; }else if(isDest){ description+=text; }else if(isPubDate){ pubDate+=text; } } }


【文件预览】:
yuedu
----bin()
--------classes.dex(23KB)
--------res()
--------dexedLibs()
--------classes()
--------resources.ap_(77KB)
--------YueduActivity.apk(91KB)
--------yuedu.apk(91KB)
--------AndroidManifest.xml(1KB)
----res()
--------drawable-ldpi()
--------drawable-hdpi()
--------drawable-xhdpi()
--------values()
--------drawable-mdpi()
--------layout()
----assets()
----gen()
--------fenghuo()
----proguard.cfg(1KB)
----.settings()
--------org.eclipse.jdt.core.prefs(177B)
----src()
--------fenghuo()
----.project(841B)
----.classpath(364B)
----project.properties(361B)
----AndroidManifest.xml(1KB)

网友评论

  • 咋不能运行?上传的看到了加我qq 645585407 多谢了