Argotic Syndication Framework生成RSS

using System.IO;
using Argotic.Syndication;

RssFeed feed = new RssFeed();

feed.Channel.Link = new Uri("http://localhost");
feed.Channel.Title = "Simple RSS Feed";
feed.Channel.Description = "A minimal RSS 2.0 syndication feed.";

RssItem item = new RssItem();
item.Title = "Simple RSS Item";
item.Link = new Uri("http://localhost/items/SimpleRSSItem.aspx");
item.Description = "A minimal RSS channel item.";

feed.Channel.AddItem(item);

using(FileStream stream = new FileStream("SimpleRssFeed.xml", FileMode.Create, FileAccess.Write))
{
feed.Save(stream);
}
例子2:
using System.IO;
using Argotic.Common;
using Argotic.Syndication;

RssFeed feed = new RssFeed();

feed.Channel.Link = new Uri("http://localhost");
feed.Channel.Title = "Compact RSS Feed";
feed.Channel.Description = "A minimal and non-indented RSS 2.0 syndication feed.";

RssItem item = new RssItem();
item.Title = "Simple RSS Item";
item.Link = new Uri("http://localhost/items/SimpleRSSItem.aspx");
item.Description = "A minimal RSS channel item.";

feed.Channel.AddItem(item);

using (FileStream stream = new FileStream("CompactRssFeed.xml", FileMode.Create, FileAccess.Write))
{
SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
settings.MinimizeOutputSize = true;

feed.Save(stream, settings);
}

如果在当前页输出可以用如下代码:

      Response.ContentType = "application/rss+xml";
        SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
        settings.CharacterEncoding = new UTF8Encoding(false);
        feed.Save(Response.OutputStream, settings); 

 

 读取的例子:

 

using Argotic.Extensions.Core;
using Argotic.Syndication;

RssFeed feed = new RssFeed(new Uri("http://example.com/feed.aspx"), "Simple extended syndication feed");
feed.Channel.Description = "An example of how to generate an extended syndication feed.";

// Create and add iTunes information to feed channel
ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension();
channelExtension.Context.Subtitle = "This feed uses the iTunes syndication extension.";
channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No;
channelExtension.Context.Author = "John Doe";
channelExtension.Context.Summary = "The Argotic syndication framework natively supports the iTunes syndication extension.";
channelExtension.Context.Owner = new ITunesOwner("john.doe@example.com", "John Q. Doe");
channelExtension.Context.Image = new Uri("http://example.com.feed_logo.jpg");

channelExtension.Context.Categories.Add(new ITunesCategory("Extensions"));
channelExtension.Context.Categories.Add(new ITunesCategory("iTunes"));

feed.Channel.AddExtension(channelExtension);

// Create and add iTunes information to channel item
RssItem item = new RssItem();
item.Title = "My Extended Channel Item";
item.Link = new Uri("http://example.com/posts/1234");
item.PublicationDate = DateTime.Now;

RssEnclosure enclosure = new RssEnclosure(47156978L, "audio/mp3", new Uri("http://example.com/myPodcast.mp3"));
item.Enclosures.Add(enclosure);

ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension();
itemExtension.Context.Author = "Jane Doe";
itemExtension.Context.Subtitle = "This channel item uses the iTunes syndication extension.";
itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item";
itemExtension.Context.Duration = new TimeSpan(1, 2, 13);
itemExtension.Context.Keywords.Add("Podcast");
itemExtension.Context.Keywords.Add("iTunes");

item.AddExtension(itemExtension);

feed.Channel.AddItem(item);

// Persist extended feed
using (FileStream stream = new FileStream("ExtendedFeed.rss.xml", FileMode.Create, FileAccess.Write))
{
feed.Save(stream);
}
 

 

 

 

转载于:https://www.cnblogs.com/xiongeee/archive/2010/04/02/1702866.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值