1

我正在尝试使用以下代码使用 RSS 提要:

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

但它会抛出一个错误:

“元素”是无效的 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/atom 提要吗?

4

1 回答 1

0

来源似乎没有验证这可能是一个问题。

测试另一个 rss 源以验证它是否可能。

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

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

于 2014-12-22T04:59:09.967 回答