随笔 - 705  文章 - 0  评论 - 1103  阅读 - 138万 

 

源地址:http://msdn.microsoft.com/zh-cn/library/system.servicemodel.syndication.syndicationfeed(v=VS.95).aspx

 

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

}
 
 读入 :
 
 
  1. WebClient webClient = new WebClient();
  2. //注册webClient读取完成事件
  3. webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
  4. {
  5. try
  6. {
  7. if (e.Error != null)
  8. {
  9. if (onError != null)
  10. {
  11. onError(e.Error);
  12. }
  13. return;
  14. }
  15. //将网络获取的信息转化成RSS实体类
  16. List<RssItem> rssItems = new List<RssItem>();
  17. Stream stream = e.Result;
  18. XmlReader response = XmlReader.Create(stream);
  19. SyndicationFeed feeds = SyndicationFeed.Load(response);
  20. foreach (SyndicationItem f in feeds.Items)
  21. {
  22. RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri);
  23. rssItems.Add(rssItem);
  24. }
源地址:http://hi.baidu.com/wuyunju/blog/item/88e6dbdd445a813c5982dd88.html
posted on   冯瑞涛  阅读(770)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
历史上的今天:
2009-10-07 LINQ 标准的查询操作符 转换 ToList()、ToLookup()、ToEnumerable()、ToDictionary、ToType<T>
2009-10-07 LINQ 标准的查询操作符 合计操作符 Count()、Sum()、Min()、Max()、Average()和Aggregate()
2009-10-07 LINQ 标准的查询操作符 分区 Take 、Skip 、TakeWhile 、SkipWhile
2009-10-07 LINQ 标准的查询操作符 设置操作符号 两个结果集的 并、交、差、唯一
2009-10-07 LINQ 标准的查询操作符 连接 join in on equals
2009-10-07 LINQ 标准的查询操作符 分组 group by into 、select new 、orderby descending、from in
点击右上角即可分享
微信分享提示