手机
当前位置:查字典教程网 >编程开发 >XML/RSS >给你的asp+ac站点加rss功能
给你的asp+ac站点加rss功能
摘要:复制代码代码如下:'这里是xml的版本和语言声明'以下相当于html的meta部分,包括标题.连接.语言.版权信息以及logo图标等简单的快...

复制代码 代码如下:

<%

Response.ContentType="text/xml"

dimdb,dbpath,conn

dimrs,SQL

db="shujuku/hotltcom.mdb"''''这里填写你的数据库地址

Setconn=Server.CreateObject("ADODB.Connection")

dbpath="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(db)

conn.Opendbpath

%>

<?xmlversion="1.0"encoding="gb2312"?><rssversion="2.0">'这里是xml的版本和语言声明

<channel>

'以下相当于html的meta部分,包括标题.连接.语言.版权信息以及logo图标等

<title>简单的快乐</title>

<link>http://siyizhu.com</link>

<Description>简单的快乐</Description>

<language>zh-cn</language>

<copyright>Copyright2006hotlt</copyright>

<webMaster>hotlt@tom.com</webMaster>

<image>

<title>简单的快乐</title>

<url>http://siyizhu.com/logo.gif</url>

<link>http://siyizhu.com/</link><description>siyizhu'sweblog</description></image>

'以下是连接数据库数据表部分,top15代表最新的15条,movie是数据表

<%

SQL="selecttop15*frommovieorderbyiddesc"

setrs=conn.execute(SQL)

ifrs.Eoforrs.Bofthen

response.write"<item></item>"

endif

whilenotrs.Eof

Title=rs("Title")'这里定义Title是标题,("Title")为字段名称

id=rs("id")'这里定义id是连接id,("id")为字段名称

Time=rs("Time")'这里定义Time是时间,("Time")为字段名称

Content=replace(replace(left(rs("Content"),200),"<","<"),">",">")'这里的Content是内容的字段名称

'以下是rss输出

response.Write"<item>"

Response.write"<title>"&Title&"</title>"'这里是输出标题

response.write"<link>http://siyizhu.com/weblog/article.asp?ID="&id&"</link>"'这里是输出链接,注意要用网址

response.write"<author>siyizhu</author>"'这里是输出作者,如果有字段可以调用字段

response.write"<PubDate>"&Time&"</PubDate>"'这里是时间

response.write"<description><![CDATA["&Content&"]]></description>"'这里是输出简介,因为可能有代码.括起来,否则预览时会提示错误。

response.write"</item>"

rs.MoveNext

wend

setrs=nothing

conn.Close

setconn=nothing

%>

</channel></rss>

注意事项:其中要注意[CDATA*]>的使用,像是内容之类的输出尽量用"[CDATA[*]]>",

*为输出内容,应为内容可能为代码形式,如有空格或asp代码.否则可能会出错误.

【给你的asp+ac站点加rss功能】相关文章:

一个简单的XML Schema的例子

XML卷之实战锦囊(5):结构树图

使用xmlhttp为网站增加域名查询功能

XML和JSP的联手

让Asp与XML交互

利用XML开发留言板简单的例子

用XML和SQL 2000来管理存储过程调用

为何XML对Web服务很重要

怎样打开XML文件?xml文件如何打开?

报错:XML页无法显示,下列标记没有被关闭解决方法

精品推荐
分类导航