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

元气小坏坏 提交于 2019-12-06 07:15:22

问题


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.


回答1:


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();
}


来源:https://stackoverflow.com/questions/5103522/asp-net-c-how-do-i-parse-an-atom-feed-from-a-blog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!