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

 

 

 

posted on 2010-04-02 09:57  冷火  阅读(459)  评论(0编辑  收藏  举报