How do I determine if a Feed is RSS or Atom in .NET with C#?


I have a list of feeds that a user provides and I do not know in advance which feed is which (RSS or Atom).

I would like to figure out how to check which format each feed is because I'm running into issues where certain SyndicationItem item's are not assecible depending on the feed type.

For example,


Works with Atom to pull off the Sumamry, but if I tried this for RSS I get an 'Object reference not set to an instance of an object' .error, but this then works:


where 'item' for both is the variable name for the SyndicationItem

So, I need to check which type of feed I'm reading in to know which summary tag to use...

Who is Participating?
Brad HoweConnect With a Mentor DevOps ManagerCommented:
Yep, that is what I would do.  First, take the raw xml as is, parse it and find those Keys.
Once you Key is found, run your feed with the appropriate tags.

Brad HoweDevOps ManagerCommented:
Why not just use a quick XML Parser before loading it. I don't have time to write up a sample at the moment but you could determine based on xml key.

ATOM Feeds start with key <feed xmlns> </feed>

RSS Feed start with key <rss> </rss>

stracqanAuthor Commented:
So before I run it through the SyndicationFeed check the XML that coming in from the web and pull out those values to determine which is which??

And then I would set a flag to know which item to use..?
stracqanAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.