Reputation: 37652
I have an exception here
var stream = e.Result;
var response = XmlReader.Create(stream);
var feeds = SyndicationFeed.Load(response); // IT IS HERE
The exception
Element 'channel' with namespace name '' was not found. Line 8, position 2.
RSS looks like:
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<atom:link href="http://dallas.example.com/rss.xml" rel="self"
type="application/rss+xml" /> <channel> <title>News</title>
<link>http://www.samsung.com/us</link> <description>News</description>
...
http://validator.w3.org/feed/ says that "This is a valid RSS feed." (You can check it here http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.samsung.com%2Fus%2Ffunction%2Frss%2FrssFeedItemList.do%3FctgryCd%3D101%26typeCd%3DNEWS)
So I have no clue whats happening... :(
Can we workaround to suppress some of the validation message of the SyndicationFeed class?
Thank you for ANY solution that will give me the chance forget about this exception!
Upvotes: 3
Views: 2363
Reputation: 13452
Thanks to Michael’s answer, I was able to pre-process the offending XML (which is not under my control) to move errant atom:link
elements:
private static readonly XName AtomLink = XName.Get( "link", "http://www.w3.org/2005/Atom" );
private static readonly XName Channel = XName.Get( "channel" );
...
var document = XDocument.Load( stream );
var channel = document.Root.Element( Channel );
foreach( var misplacedLink in document.Root.Elements( AtomLink ) ) {
misplacedLink.Remove( );
channel.Add( misplacedLink );
}
using( var reader = document.CreateReader( ) )
return SyndicationFeed.Load( reader );
Upvotes: 1
Reputation: 1282
If you look at the results from the W3 validation you listed, it reads:
line 8, column 0: Undocumented use of atom:link
The atom:link
element being placed before the channel
element is causing the SyndicationFeed
class to fail on load. You can test this yourself by downloading the rss feed xml locally, removing/commenting the atom:link
line and running your code again. Without that line, the xml loads and the feeds are found. This has happened before with the SyndicationFeed
class.
Upvotes: 4