0

目前,这是我从 Yahoo! 获得的 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>

description在我的 UI 控件中显示内容对我来说非常简单。我可以自己决定我的 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&amp;fd=R&amp;usg=AFQjCNE006d3wlqjgGfQAqGV8S4VFtQY3g&amp;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&#39;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&amp;ned=us"><nobr><b>and more&nbsp;&raquo;</b></nobr></a></font></div></font></td></tr></table>
    </description>
</item>

如您所见,description它带有各种 HTML 标签,这不符合我的兴趣。我只对纯内容感兴趣,而不是格式信息。

有什么简单的方法可以实现我的目标吗?

4

2 回答 2

1

该类Html具有fromHtml()从字符串中删除任何标签的方法:

String noHtml = Html.fromHtml(HTML_STRING).toString();

见这里: http: //developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String)

于 2013-10-02T12:28:49.427 回答
0

您可以使用 XSLT 将 xml 输入转换为 xml 输出,在这种情况下,您将创建一个匹配描述的模板匹配器,然后仅将文本复制到输出中,直到描述标记结束。

于 2013-10-02T12:21:30.917 回答