Tom Gullen
Tom Gullen

Reputation: 61735

ASP.net c#. How do I parse an atom feed from a blog

The feed is at:

http://latestpackagingnews.blogspot.com/feeds/posts/default

The tags I want are:

<entry>
    <published></published>
    <title></title>
    <content></content>
</entry>

I don't care about anything else, all I want to do is loop these! Please don't post tutorial links I've tried a bunch and just can't get any to work. Treat me like an idiot please.

Upvotes: 3

Views: 6821

Answers (1)

J. Tihon
J. Tihon

Reputation: 4459

You can take a look at the System.ServiceModel.Syndication.Atom10FeedFormatter class. (System.ServiceModel.dll)

static void Main(string[] args)
{
    Atom10FeedFormatter formatter = new Atom10FeedFormatter();
    using (XmlReader reader = XmlReader.Create("http://latestpackagingnews.blogspot.com/feeds/posts/default"))
    {
        formatter.ReadFrom(reader);
    }

    foreach (SyndicationItem item in formatter.Feed.Items)
    {
        Console.WriteLine("[{0}][{1}] {2}", item.PublishDate, item.Title.Text, ((TextSyndicationContent)item.Content).Text);
    }

    Console.ReadLine();
}

Upvotes: 11

Related Questions