2013-10-02 21 views
0

目前,這裏是RSS新聞,我從雅虎獲得刪除HTML從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控件中的內容。我可以自己決定用戶界面的外觀(字體大小,字體顏色)。

然而,事情變得更加困難,如果我是谷歌從檢索內容!

下面是一個例子

<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標籤,這是我的興趣的一起。我只對簡單的內容感興趣,而不是格式化信息。

有沒有簡單的方法,我可以實現我的目標?

回答

0

您可以使用XSLT將XML輸入轉換爲XML輸出,在這種情況下,您將創建一個模板匹配描述匹配的,從那時起,只有等到說明標籤結束文本複製到輸出。