.NET 3.5 : 读写RSS或者ATOM
2020-11-15 01:36
标签:des com http blog class img code log c tar ext 在.NET 3.5中提供了一套全新的接口来实现对RSS和ATOM这两种数据文件的读写。非常方便。下面演示一下 1. 首先要添加一个引用System.ServiceModel.Web using System.ServiceModel.Syndication; 2. 读取RSS的代码 /// dgvResult.DataSource = items.ToArray(); 效果如下 3. 写入RSS的代码如下 /// XmlWriter xw =
XmlWriter.Create("rss.xml"); 效果如下 4. 结合ashx实现网站的RSS整合 using System; namespace WebApplication1 public void
ProcessRequest(HttpContext
context) XmlWriter
xw =
XmlWriter.Create(context.Response.OutputStream); public bool
IsReusable 在客户端读取的效果如下 5. 结合数据库的案例 using System; namespace WebApplication1 public void
ProcessRequest(HttpContext
context) DataTable
tb = new
DataTable(); var items
= from DataRow row in
tb.Rows
SyndicationFeed feed = new
SyndicationFeed( XmlWriter
xw =
XmlWriter.Create(context.Response.OutputStream); public bool
IsReusable 原文地址:http://www.cnblogs.com/chenxizhang/archive/2009/07/16/1525000.html .NET 3.5 : 读写RSS或者ATOM,布布扣,bubuko.com .NET 3.5 : 读写RSS或者ATOM 标签:des com http blog class img code log c tar ext 原文地址:http://www.cnblogs.com/tuyile006/p/3695684.html
using System.Xml;
/// 从一个远程站点读取RSS
///
///
///
private void btLoad_Click(object sender, EventArgs
e)
{
SyndicationFeed feed =
SyndicationFeed.Load(XmlReader.Create(feedaddress.Text));
var items = from item in
feed.Items
where
item.Title.Text.Contains("VSTS")
orderby item.PublishDate
descending
select new { Id = item.Id, Title = item.Title.Text };
}
/// 构造一个RSS
///
///
///
private void btCreate_Click(object sender,
EventArgs e)
{
SyndicationFeed feed = new
SyndicationFeed(
"我的博客",
"陈希章的博客",
new Uri("http://www.xizhang.com/"),
new[]{
new
SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx")),
new SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx")),
new SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx"))
}
);
feed.SaveAsRss20(xw);
xw.Close();
}
using System.Web;
using System.Web.Services;
using
System.ServiceModel.Syndication;
using System.Xml;
{
///
/// $codebehindclassname$
的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
public class RSS :
IHttpHandler
{
{
SyndicationFeed feed = new
SyndicationFeed(
"我的博客",
"陈希章的博客",
new Uri("http://www.xizhang.com/"),
new[]{
new SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx")),
new SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx")),
new SyndicationItem("测试博客标题", "博客内容", new Uri("http://www.xizhang.com/test.aspx"))
}
);
feed.SaveAsRss20(xw);
xw.Close();
context.Response.End();
}
{
get
{
return
false;
}
}
}
}
using System.Web;
using System.Web.Services;
using
System.ServiceModel.Syndication;
using System.Xml;
using
System.Data;
using System.Linq;
{
///
/// $codebehindclassname$
的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
public class RSS :
IHttpHandler
{
{
tb.Columns.AddRange(
new[]{
new
DataColumn("Title"),
new
DataColumn("Contents"),
new
DataColumn("Link")
});
//这里可以假设读取一些数据过来
select new SyndicationItem(row.Field
"我的博客",
"陈希章的博客",
new Uri("http://www.xizhang.com/"),
items.ToArray()
);
feed.SaveAsRss20(xw);
xw.Close();
context.Response.End();
}
{
get
{
return
false;
}
}
}
}