SyndicationFeed.Load throwing 'Element' is an invalid XmlNodeType.

630 views Asked by At

I'm attempting to consume an RSS feed using this code:

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. Line 16, position 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?

Is there something better I should use to process RSS/atom feeds?

1

There are 1 answers

0
Dennie On

The source does not seem to validate which could be a problem.

Test another rss source to verify it mabye.

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.