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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 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了