当前位置 博文首页 > 给你的asp+ac站点加rss功能

    给你的asp+ac站点加rss功能

    作者:admin 时间:2021-09-01 19:07

    复制代码 代码如下:

    <%
    Response.ContentType="text/xml"
    dim db,dbpath,conn
    dim rs,SQL
    db="shujuku/hotltcom.mdb"''''这里填写你的数据库地址
    Set conn = Server.CreateObject("ADODB.Connection")
    dbpath="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
    conn.Open dbpath
    %>
    <?xml version="1.0" encoding="gb2312"?><rss version="2.0">'这里是xml的版本和语言声明
    <channel>
    '以下相当于html的meta部分,包括标题.连接.语言.版权信息以及logo图标等
    <title>简单的快乐</title>
    <link>http://siyizhu.com</link>
    <Description>简单的快乐</Description>
    <language>zh-cn</language>
    <copyright>Copyright 2006 hotlt</copyright>
    <webMaster>hotlt@tom.com</webMaster>
    <image>
    <title>简单的快乐</title> 
    <url>http://siyizhu.com/logo.gif</url> 
    <link>http://siyizhu.com/</link><description>siyizhu's weblog</description></image>
    '以下是连接数据库数据表部分,top 15代表最新的15条,movie是数据表
    <%
    SQL="select top 15 * from movie order by id desc"
    set rs=conn.execute(SQL)
    if rs.Eof or rs.Bof then
    response.write "<item></item>"
    end if
    while not rs.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 
    set rs=nothing
    conn.Close
    set conn = nothing
    %>
    </channel></rss>

    注意事项:其中要注意[CDATA*]>的使用,像是内容之类的输出尽量用"[CDATA[ * ]]>",
    *为输出内容,应为内容可能为代码形式,如有空格或asp代码.否则可能会出错误. 
    jsjbwy
下一篇:没有了