Создание RSS и Atom ленты в .NET 3.5

Это стало еще проще, в .NET 3.5 появился namespace System.ServiceModel.Syndication

Простой пример:

private void WriteRss(List<Doc> docList)
    {

        Response.Buffer = false;
        Response.Clear();
        Response.ContentType = "application/xml";

        using (XmlWriter writer = XmlWriter.Create(Response.OutputStream))
        {
            SyndicationFeed feed = new SyndicationFeed
                ("Название",
                "Описание",
                new Uri(http://урл));

            feed.Copyright = new TextSyndicationContent
                ("© Copyright");

            feed.Generator = "FlashEngine";

            feed.Language = "ru-RU";

            List<SyndicationItem> items = new List<SyndicationItem>();

            foreach (Doc doc in docList)
            {
                SyndicationItem item = new SyndicationItem();

                item.AddPermalink(new Uri("http://url" + doc.Url));
                item.Title = TextSyndicationContent.CreatePlaintextContent(doc.Title);
                item.Content = SyndicationContent.CreateXhtmlContent(doc.Text);
                item.PublishDate = doc.PublishDateTime;
                items.Add(item);

            }
            feed.Items = items;

            Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(feed);
            rssFormatter.WriteTo(writer);
            writer.Flush();
        }

        Response.End();
    }

9 апреля 2008 г. 15:34

Комментарии

Комментариев пока нет.

Добавить комментарий






 
Copyright © Антон Ковалев