简体   繁体   English

XML 2.0 RSS feed处理Android

[英]XML 2.0 RSS Feeds Processing Android

Have a look at the feed here . 看一下这里提要 It is easy to process XML 1.0 / 1.1 where they only have normal characters in the <description> tag. XML 1.0 / 1.1很容易处理,其中<description>标记中只有普通字符。 However, the RSS feed mentioned above has HTML tags like <strong> , <em> , etc and not to mention, JavaScript function calls and special characters. 但是,上面提到的RSS feed具有HTML标签,例如<strong><em>等,更不用说JavaScript函数调用和特殊字符了。

What I, as a beginner to Android, do is to make my own SAX parser to get the data from specific tags, put them into objects that represent feeds and make an ArrayList / Vector out of them. 作为Android的初学者,我要做的是制作自己的SAX解析器,以从特定标签中获取数据,将其放入代表提要的对象中,并从中创建ArrayList / Vector All I get is character data in the characters(..) callback method of DefaultHandler . 我得到的只是DefaultHandlercharacters(..)回调方法中的字符数据。

Now, how do I properly display this text with all the HTML formatting, the JavaScript function calls, etc in Android? 现在,如何在Android中使用所有HTML格式, JavaScript函数调用等正确显示此文本?

I mean, the one who made the RSS feeds for this put it all this in because they wanted the feeds to hav a certain look-and-feel. 我的意思是,为此编写RSS feed的人将所有内容都放入其中,因为他们希望这些feed具有某种外观。 Please help me with this. 请帮我解决一下这个。

Don't reinvent the wheel.. 不要重新发明轮子。

As recommended here ,use android-rss library to read parts of RSS 2.0 feeds.I have used it in my project and it works brilliantly.. 作为推荐这里 ,使用Android系统的RSS图书馆阅读RSS 2.0 feeds.I的部分已经在我的项目中使用它,它出色的作品..

  RSSReader reader = new RSSReader();
  RSSFeed feed = reader.load(feedUrl);
  List<RSSItem> list = feed.getItems();
  for (RSSItem i: list) 
  {
    i.getTitle();//title content
    i.getDescription();//description content
    i.getLink();//link
  }

To view the description content use Html.fromHtml which would return styled text.. 要查看描述内容,请使用Html.fromHtml ,它将返回样式化的文本。

TextView textView= (TextView)findViewById(R.id.textView1);
textView.setText(Html.fromHtml(descriptionContent));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM