SyndicationFeed.Load抛出'Element'是无效的XmlNodeType。

时间:2014-12-22 04:30:20

标签: c# .net rss atom-feed syndicationfeed

我正在尝试使用此代码使用RSS Feed:

var reader = XmlReader.Create("http://www.news-herald.com/section?template=RSS&profile=4002042&mime=xml");
var syndicationFeed = SyndicationFeed.Load(reader);

但它引发了一个错误:

  

'Element'是无效的XmlNodeType。第16行,第6位。

这表示自闭“源”标记下方的行:

<source url="http://www.news-herald.com/general-news/20141219/new-richmond-heights-website-expected-to-be-ready-by-april"/>
<description><![CDATA[<p>Richmond Heights is officially replacing the website it has been using since 2006. </p><p>City Council members approved a contract with Cuyahoga County Department of Information Technology at its most recent meeting to design a new website for the city. </p><p>It is projected to cost $5,293 with the contract not to exceed $7,000.</p>]]></description>

如果我手动将源标记修改为以“”结尾并使用该测试文件,则会正确处理。

我可以自动让SyndicationFeed或XmlReader自动执行此操作吗?

我应该使用哪些更好的东西来处理RSS /原子供稿?

1 个答案:

答案 0 :(得分:0)

来源似乎不是validate,这可能是一个问题。

测试另一个rss源以验证它是否为mabye。

The feed appears to be encoded as "UTF-8", but the server is reporting "iso-8859-1"

您可以尝试将源读入XDocument,将编码更改为您想要的,然后尝试加载它。