protected override void OnLoad(EventArgs e)
{
SyndicationFeed feed = new SyndicationFeed("商户信息", "提供商户信息列表", new Uri("http://www.pumaboyd.com/feed"));
Collection<SyndicationItem> items = new Collection<SyndicationItem>();
foreach (var shop in RssData.GetShops())
{
SyndicationItem item = new SyndicationItem();
item.Title = new TextSyndicationContent(shop.ShopName + shop.BranchName);
item.Content = new TextSyndicationContent(shop.Address);
item.Summary = new TextSyndicationContent(shop.Address);
item.Links.Add(new SyndicationLink(new Uri("http://www.pumaboyd.com/shop/" + shop.ShopID)));
item.Authors.Add(new SyndicationPerson("pumaboyd@163.com",shop.AddUser,"http://www.pumaboyd.com"));
item.PublishDate = shop.AddTime;
item.Id = "http://www.pumaboyd.com/shop/" + shop.ShopID;
items.Add(item);
}
feed.Items = items;
Response.ContentType = "application/rss+xml";
var output = new StringWriter();
var writer = new XmlTextWriter(output);
feed.SaveAsRss20(writer);
Response.Write(output.ToString());
}
读入 :
- WebClient webClient = new WebClient();
- //注册webClient读取完成事件
- webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
- {
- try
- {
- if (e.Error != null)
- {
- if (onError != null)
- {
- onError(e.Error);
- }
- return;
- }
- //将网络获取的信息转化成RSS实体类
- List<RssItem> rssItems = new List<RssItem>();
- Stream stream = e.Result;
- XmlReader response = XmlReader.Create(stream);
- SyndicationFeed feeds = SyndicationFeed.Load(response);
- foreach (SyndicationItem f in feeds.Items)
- {
- RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri);
- rssItems.Add(rssItem);
- }
源地址:http://hi.baidu.com/wuyunju/blog/item/88e6dbdd445a813c5982dd88.html
冯瑞涛