惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
News and Events Feed by Topic
P
Privacy International News Feed
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
月光博客
月光博客
D
Docker
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
S
Security Affairs
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
Lohrmann on Cybersecurity
T
Threatpost
量子位
S
Schneier on Security
V
Visual Studio Blog
S
Securelist
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
小众软件
小众软件
罗磊的独立博客
雷峰网
雷峰网
Recorded Future
Recorded Future

博客园 - aimar

常见的 Web 项目转换问题及解决方案(转载) 在VS2005 正确地创建、部署和维护由1.1迁移到ASP.NET 2.0 应用程序 ajax用户控件中读取session的问题 - aimar - 博客园 世界杯分组与赛程 可否在vs2005中开发asp.net1.1的项目? 试用了一下google的个性化主页 Asp.net WebControls基本概念 连接sql2005 SqlServer2000的xml功能 DotNet2.0中上传文件 - aimar - 博客园 Oracle相关资源 关于使用存储过程的一些好处以及注意事项 DataGrid生成序号列 - aimar - 博客园 asp.net常用函数 Asp.Net2.0编译模式 Asp.Net2.0的改变 ASP.NET 2.0 Beta2中页面编译模型的变化 数据库访问程序块的效率问题 Rss应用(二) 抽取Rss
Rss应用(一) 创建rss
aimar · 2006-01-05 · via 博客园 - aimar

rss现在很流行,它推行的一套xml格式的标准来传输数据,和webservice差不多,不过它必须遵从一套它自己的标准。

创建rss有很多种方式,最终的目的是形成一个xml文档的输出流,这个文档要符合一定的标准格式。找到一种比较简单的形成rss的方法,使用repeater来绑定重复的xml节点。

新建一个webform    Rss.aspx,在html视图中删除除了第一行页面声明以外的其它代码,写上以下xml格式的代码

 1<%@ Page language="c#" Codebehind="Rss.aspx.cs" AutoEventWireup="false" Inherits="RSSReader.Rss" %>
 2<?xml version="1.0" ?> 
 3<rss version="2.0">
 4  <channel>
 5    <title>测试rss</title>        
 6    <link>http://zqs.cnblogs.com/</link>
 7    <description>测试rss</description>
 8    <language>zh-cn</language>
 9   <asp:Repeater id="Repeater1" runat="server">
10   <ItemTemplate>
11        <item>
12        <title><%#DataBinder.Eval(Container.DataItem,"sch_name")%></title>
13        <description><![CDATA[<%#DataBinder.Eval(Container.DataItem,"sch_name")%>]]></description>
14        <pubDate><%#((DateTime)DataBinder.Eval(Container.DataItem,"indate")).ToString("r"%></pubDate>
15        <link>http://zqs.cnblogs.com/show.aspx?id=<%# DataBinder.Eval(Container.DataItem, "sch_no"%></link>
16        </item>
17      </ItemTemplate>
18</asp:Repeater>
19</channel>
20</rss>
21


代码说明:

 建立一个xml格式的文档,然后用Repeater来重复显示数据行节点

该页面的后置代码文件Rss.cs中的代码如下,在该页面的Page_Load事件中写上如下代码:

 1    SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=;");
 2
 3            System.Data.SqlClient.SqlDataAdapter myComm = new SqlDataAdapter("select * from dSchool",conn);
 4
 5            DataSet ds = new DataSet();
 6
 7            myComm.Fill(ds,"Table1");
 8        
 9            Response.ContentType="Text/XML";
10            Repeater1.DataSource = ds;
11
12            Repeater1.DataBind();

代码说明:

   使用Response.ContentType="Text/XML";将页面的输出流设置为xml格式,其它就是得到数据集绑定Repeater了