您的位置:首页 > 编程语言 > ASP

转载:ASP.net RSS 订阅输出 SyndicationFeed

2011-10-07 11:44 211 查看
源地址:http://msdn.microsoft.com/zh-cn/library/system.servicemodel.syndication.syndicationfeed(v=VS.95).aspx
protectedoverridevoidOnLoad(EventArgse)
{

SyndicationFeedfeed=newSyndicationFeed("商户信息","提供商户信息列表",newUri("http://www.pumaboyd.com/feed"));

Collection<SyndicationItem>items=newCollection<SyndicationItem>();

foreach(varshopinRssData.GetShops())
{
SyndicationItemitem=newSyndicationItem();
item.Title=newTextSyndicationContent(shop.ShopName+shop.BranchName);
item.Content=newTextSyndicationContent(shop.Address);
item.Summary=newTextSyndicationContent(shop.Address);
item.Links.Add(newSyndicationLink(newUri("http://www.pumaboyd.com/shop/"+shop.ShopID)));
item.Authors.Add(newSyndicationPerson("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";
varoutput=newStringWriter();
varwriter=newXmlTextWriter(output);
feed.SaveAsRss20(writer);
Response.Write(output.ToString());

}
读入:


WebClientwebClient=newWebClient();

//注册webClient读取完成事件
webClient.OpenReadCompleted+=delegate(objectsender,OpenReadCompletedEventArgse)
{
try
{

if(e.Error!=null)
{
if(onError!=null)
{
onError(e.Error);
}
return;
}

//将网络获取的信息转化成RSS实体类
List<RssItem>rssItems=newList<RssItem>();
Streamstream=e.Result;
XmlReaderresponse=XmlReader.Create(stream);
SyndicationFeedfeeds=SyndicationFeed.Load(response);
foreach(SyndicationItemfinfeeds.Items)
{
RssItemrssItem=newRssItem(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: