Java 仅从RSS源读取特定标记
我正试图学习如何通过以下步骤为我的android应用程序制作RSS阅读器。 该提要是从wordpress博客生成的,我想找出一种按类别阅读的方法。它目前正在读取整个提要项,但我正试图从列表中整理出特定的类别 这是阅读提要的活动类Java 仅从RSS源读取特定标记,java,android,wordpress,xml-parsing,rss-reader,Java,Android,Wordpress,Xml Parsing,Rss Reader,我正试图学习如何通过以下步骤为我的android应用程序制作RSS阅读器。 该提要是从wordpress博客生成的,我想找出一种按类别阅读的方法。它目前正在读取整个提要项,但我正试图从列表中整理出特定的类别 这是阅读提要的活动类 // Connected - Start parsing new AsyncLoadXMLFeed().execute(); } } private void startLisActivity(RSSFeed feed) { Bu
// Connected - Start parsing
new AsyncLoadXMLFeed().execute();
}
}
private void startLisActivity(RSSFeed feed) {
Bundle bundle = new Bundle();
bundle.putSerializable("feed", feed);
// launch List activity
Intent intent = new Intent(SplashActivity.this, GridActivity.class);
intent.putExtras(bundle);
startActivity(intent);
// kill this activity
finish();
}
private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Obtain feed
DOMParser myParser = new DOMParser();
feed = myParser.parseXml(http://mywordpressblog.com/feed/);
if (feed != null && feed.getItemCount() > 0)
WriteFeed(feed);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
startLisActivity(feed);
}
}
// Method to write the feed to the File
private void WriteFeed(RSSFeed data) {
FileOutputStream fOut = null;
ObjectOutputStream osw = null;
try {
fOut = openFileOutput(fileName, MODE_PRIVATE);
osw = new ObjectOutputStream(fOut);
osw.writeObject(data);
osw.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Method to read the feed from the File
private RSSFeed ReadFeed(String fName) {
FileInputStream fIn = null;
ObjectInputStream isr = null;
RSSFeed _feed = null;
File feedFile = getBaseContext().getFileStreamPath(fileName);
if (!feedFile.exists())
return null;
try {
fIn = openFileInput(fName);
isr = new ObjectInputStream(fIn);
_feed = (RSSFeed) isr.readObject();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
fIn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return _feed;
}
//已连接-开始解析
新建AsyncLoadXMLFeed().execute();
}
}
私人无效输入活动(RSSFeed馈送){
Bundle=新Bundle();
bundle.putSerializable(“提要”,提要);
//启动列表活动
意向意向=新意向(SplashActivity.this、GridActivity.class);
意向。额外支出(捆绑);
星触觉(意向);
//终止此活动
完成();
}
私有类AsyncLoadXMLFeed扩展了AsyncTask{
@凌驾
受保护的Void doInBackground(Void…参数){
//获取饲料
DOMParser myParser=新的DOMParser();
feed=myParser.parseXml(http://mywordpressblog.com/feed/);
if(feed!=null&&feed.getItemCount()>0)
写进(进);
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
惊吓活性(feed);
}
}
//方法将提要写入文件
专用void WriteFeed(RSSFeed数据){
FileOutputStream fOut=null;
ObjectOutputStream osw=null;
试一试{
fOut=openFileOutput(文件名,模式\私有);
osw=新对象输出流(fOut);
osw.writeObject(数据);
osw.flush();
}
捕获(例外e){
e、 printStackTrace();
}
最后{
试一试{
fOut.close();
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
//方法从文件中读取提要
专用RSSFeed ReadFeed(字符串fName){
FileInputStream fIn=null;
ObjectInputStream isr=null;
RSSFeed _feed=null;
File feedFile=getBaseContext().getFileStreamPath(文件名);
如果(!feedFile.exists())
返回null;
试一试{
fIn=openFileInput(fName);
isr=新目标输入流(fIn);
_提要=(RSSFeed)isr.readObject();
}
捕获(例外e){
e、 printStackTrace();
}
最后{
试一试{
fIn.close();
}捕获(IOE异常){
e、 printStackTrace();
}
}
返回(u)馈送;;
}
在将项目添加到列表中之前,您可以这样检查:
如果(item.getCategory()包含(“categorytoshow”)){
将其添加到列表中,因为它包含所需的类别
}
然后将其添加到列表中