目前,这是我从雅虎获得的RSS新闻源!
<item>
<title>
Cheapest Stocks in Egypt Post Best Rally in Year on Army Control
</title>
<link>http://us.rd.yahoo.com/finance/external/bloomberg/rss/SIG=13gf1d488/*http://www.bloomberg.com/news/2013-10-01/cheapest-stocks-in-egypt-post-best-rally-in-year-on-army-control.html?cmpid=yhoo
</link>
<description>
[at Bloomberg] - Egyptian stocks posted their best quarter in a year as increased political stability combined with the world’s cheapest equities lured investors.
</description>
<guid isPermaLink="false">yahoo_finance/1833836173</guid>
<pubDate>Tue, 01 Oct 2013 22:00:00 GMT</pubDate>
</item>
对我来说,在我的UI控件中显示description
的内容非常简单。我可以自己决定我的UI外观(字体大小,字体颜色)。
但是,如果我从Google检索内容,事情会变得更加困难!
这是一个例子
<item>
<title>Genting, UMW weigh on KLCI - The Star Online</title>
<link>http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNE006d3wlqjgGfQAqGV8S4VFtQY3g&url=http://www.thestar.com.my/Business/Business-News/2013/09/25/Genting-UMW-weigh-on-KLCI.aspx
</link>
<guid isPermaLink="false">tag:news.google.com,2005:cluster=http://www.thestar.com.my/Business/Business-News/2013/09/25/Genting-UMW-weigh-on-KLCI.aspx</guid>
<pubDate>Wed, 25 Sep 2013 01:21:04 GMT</pubDate>
<description>
<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><a href="http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNE006d3wlqjgGfQAqGV8S4VFtQY3g&url=http://www.thestar.com.my/Business/Business-News/2013/09/25/Genting-UMW-weigh-on-KLCI.aspx"><b>Genting, UMW weigh on KLCI</b></a><br /><font size="-1"><b><font color="#6f6f6f">The Star Online</font></b></font><br /><font size="-1">KUALA LUMPUR: <b>Malaysia's</b> blue chips extended their losses for third day on Wednesday, with the FBM KLCI opened down nearly five points on mild selling of Genting <b>Bhd</b>, UMW and BAT, in line with the subdued Asian bourses. At 9am, the KLCI was down 4.42 <b>...</b></font><br /><font size="-1" class="p"></font><br /><font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=dQyXEqkX7SN2KKM&ned=us"><nobr><b>and more »</b></nobr></a></font></div></font></td></tr></table>
</description>
</item>
正如您所看到的,description
附带了各种HTML标记,这不符合我的兴趣。我只关注普通内容,而不是格式化信息。
有什么简单的方法可以实现我的目标吗?
答案 0 :(得分:1)
Html
类使用fromHtml()
方法从字符串中删除任何标记:
String noHtml = Html.fromHtml(HTML_STRING).toString();
见这里:http://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String)
答案 1 :(得分:0)
您可以使用XSLT将xml输入转换为xml输出,在这种情况下,您将创建与描述匹配的模板匹配器,然后从此开始只将文本复制到输出中,直到描述标记结束。