简体   繁体   English

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

[英]SyndicationFeed.Load throwing 'Element' is an invalid XmlNodeType.

I'm attempting to consume an RSS feed using this code: 我正在尝试使用以下代码使用RSS提要:

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

But it throws an error: 但这会引发错误:

'Element' is an invalid XmlNodeType. “元素”是无效的XmlNodeType。 Line 16, position 6. 第16行,位置6。

Which is indicating the line below a self closed "source" tag: 这表示自封闭的“源”标签下方的行:

<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>

If I manually modify the source tags to end with "" and use that test file it processes properly. 如果我手动修改源标记以“”结尾并使用该测试文件,则它将正确处理。

Can I get the SyndicationFeed or the XmlReader to do this automatically for me? 我可以让SyndicationFeed或XmlReader为我自动执行此操作吗?

Is there something better I should use to process RSS/atom feeds? 我应该使用更好的方法来处理RSS / atom提要吗?

The source does not seem to validate which could be a problem. 消息来源似乎没有证实这可能是一个问题。

Test another rss source to verify it mabye. 测试另一个rss来源以验证它是否存在。

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

You could might try to read the source into an XDocument, change the encoding to what you want, and then try to load it. 您可能会尝试将源代码读入XDocument,将编码更改为所需的格式,然后尝试加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM