我正在C#中製作一個簡單的RSS閱讀器應用程序。這是我第一次使用XML,並且需要一些幫助來解析各種rss提要中使用的不同樣式。解析XML時出現問題?
如
以下是飼料的類型,我期待並獲得正確的結果有:
<item>
<title>Cometh the hour, cometh the man</title>
<link>http://www.espnstar.com/rss-feed/detail/item612327</link>
<description>Real Madrid have finally won their first trophy since 2008. Unsurprisingly, it has coincided with the arrival of one man.</description>
<pubDate>Thu, 21 Apr 2011 04:11:42 GMT</pubDate>
</item>
但飼料,如:
<item><title>NBA: San Antonio Spurs rally to level up with Memphis Grizzlies</title>
<link>http://timesofindia.feedsportal.com/c/33039/f/533921/s/1455e7bf/l/0Ltimesofindia0Bindiatimes0N0Csports0Cnba0Ctop0Estories0CNBA0ESan0EAntonio0ESpurs0Erally0Eto0Elevel0Eup0Ewith0EMemphis0EGrizzlies0Carticleshow0C80ABcms/story01.htm</link>
<description>The San Antonio Spurs, trailed by three points at half-time, rallied to level their first round playoff series with the Memphis Grizzlies at 1-1 with a 93-87 victory.<img width='1' height='1' src='http://timesofindia.feedsportal.com/c/33039/f/533921/s/1455e7bf/mf.gif' border='0'/><div class='mf-viral'><table border='0'><tr><td valign='middle'><a href="http://res.feedsportal.com/viral/sendemail2.html?title=NBA%3A+San+Antonio+Spurs+rally+to+level+up+with+Memphis+Grizzlies&link=http%3A%2F%2Ftimesofindia.indiatimes.com%2Fsports%2Fnba%2Ftop-stories%2FNBA-San-Antonio-Spurs-rally-to-level-up-with-Memphis-Grizzlies%2Farticleshow%2F8044321.cms" target="_blank"><img src="http://res3.feedsportal.com/images/emailthis2.gif" border="0" /></a></td><td valign='middle'><a href="http://res.feedsportal.com/viral/bookmark.cfm?title=NBA%3A+San+Antonio+Spurs+rally+to+level+up+with+Memphis+Grizzlies&link=http%3A%2F%2Ftimesofindia.indiatimes.com%2Fsports%2Fnba%2Ftop-stories%2FNBA-San-Antonio-Spurs-rally-to-level-up-with-Memphis-Grizzlies%2Farticleshow%2F8044321.cms" target="_blank"><img src="http://res3.feedsportal.com/images/bookmark.gif" border="0" /></a></td></tr></table></div><br/><br/><a href="http://da.feedsportal.com/r/100752217265/u/242/f/533921/c/33039/s/1455e7bf/a2.htm"><img src="http://da.feedsportal.com/r/100752217265/u/242/f/533921/c/33039/s/1455e7bf/a2.img" border="0"/></a></description>
<pubDate>Thu, 21 Apr 2011 04:33:44 GMT</pubDate>
</item>
我如何提取主要描述文本從描述節點而不是像hrefs的其他東西。
如何像飼料處理CDATA:
<item>
<title><![CDATA[Japan declares no-go zone around nuclear plant ]]></title>
<author><![CDATA[AP]]></author>
<category><![CDATA[International]]></category>
<link>http://www.thehindu.com/news/international/article1714401.ece</link>
<description><![CDATA[
Japan declared a 20 km evacuation zone around its tsunami-crippled nuclear power plant a no-go zone on Thursday, urging residents to abide by the order for the sake of their own safety. Chi...
]]>
</description>
<pubDate><![CDATA[Thu, 21 Apr 2011 08:15:48 +0530]]></pubDate>
</item>
<item>
不太確定,但我沒有弄錯,如果編碼的HTML是收到的CDATA描述的一部分,上述正則表達式將不起作用。您可能需要首先使用描述的「HtmlDecode」,然後使用正則表達式。 – Ahmad 2011-04-21 06:24:08