Solved

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

Posted on 2011-02-18
4
797 Views
Last Modified: 2012-06-27
Hello,

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,

((System.ServiceModel.Syndication.TextSyndicationContent)item.Content).Text

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:

item.Summary.Text

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

Thanks!!!!!!!!
0
Comment
Question by:stracqan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Brad Howe
ID: 34929304
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>

Cheers,
Hades666
0
 

Author Comment

by:stracqan
ID: 34929377
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..?
0
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
ID: 34929402
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.

cheers,
Hades666
0
 

Author Closing Comment

by:stracqan
ID: 34929417
thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question