ASP code applicable to RSS and XML aggregation functions of all websites

Source: Internet
Author: User

RSS. asp format
Below Code Save as RSS. asp Copy code The Code is as follows: <! -- # Include file = "conn. asp" -->
<%
Strurl = "http: //" & request. servervariables ("SERVER_NAME ")&_
Left (request. servervariables ("script_name"), Len (request. servervariables ("script_name")-len ("/RSS. ASP ") // In/RSS. ASP: name of your file

SQL = "select Top 100 * from [Table name] Order by ID DESC" // according to your actual modification, top 100 is the latest 100, you can modify it yourself, and you can add query conditions, for example, where xxx = 1 ....
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 1, 1
Response. contenttype = "text/XML"
Response. Write "<? XML version = "" 1.0 "" encoding = "" gb2312 ""?> "& Vbcrlf
Response. Write "<RSS version =" 2.0 ">" & vbcrlf
Response. Write "<channel>" & vbcrlf
Response. Write "<title> xxx.com RSS feed </title>" & vbcrlf
Response. Write "<link>" & strurl & "</link>" & vbcrlf
Response. Write "<language> ZH-CN </language>" & vbcrlf
Response. Write "<copyright> an RSS feed for XXX. comcopyright>" & vbcrlf
While not Rs. EOF
Response. Write "<item>" & vbcrlf
Response. Write "<title> <! [CDATA ["& RS (" title ") &"]> </title> "& vbcrlf
Response. Write "<link>" & strurl "/xxxx. asp? Id = "& RS (" ID ")" </link> "& vbcrlf
Response. Write "<description> <! [CDATA ["& RS (" topic field ") &" <br/> "& RS (" content field ") & "<br/>]> </description>" & vbcrlf
Response. Write "<pubdate>" & return_rfc822_date (RS ("time field"), "GMT") & "</pubdate>" & vbcrlf
Response. Write "</item>" & vbcrlf
Rs. movenext
Wend
Response. Write "</channel>" & vbcrlf
Response. Write "</RSS>" & vbcrlf
Rs. Close
Set rs = nothing

Function return_rfc822_date (byval mydate, byval timezone)
Dim myday, mydays, mymonth, myyear
Dim myhours, myminutes, myseconds

Mydate = cdate (mydate)
Myday = enweekdayname (mydate)
Mydays = right ("00" & Day (mydate), 2)
Mymonth = enmonthname (mydate)
Myyear = year (mydate)
Myhours = right ("00" & hour (mydate), 2)
Myminutes = right ("00" & minute (mydate), 2)
Myseconds = right ("00" & Second (mydate), 2)

Return_rfc822_date = myday ","&_
Mydays ""&_
Mymonth ""&_
Myyear ""&_
Myhours ":"&_
Myminutes ":"&_
Myseconds ""&_
"" & Timezone
End Function

Function enweekdayname (inputdate)
Dim result
Select case weekday (inputdate, 1)
Case 1: Result = "Sun"
Case 2: Result = "mon"
Case 3: Result = "Tue"
Case 4: Result = "wed"
Case 5: Result = "Thu"
Case 6: Result = "fri"
Case 7: Result = "sat"
End select
Enweekdayname = Result
End Function

Function enmonthname (inputdate)
Dim result
Select case month (inputdate)
Case 1: Result = "Jan"
Case 2: Result = "FEB"
Case 3: Result = "Mar"
Case 4: Result = "APR"
Case 5: Result = "may"
Case 6: Result = "Jun"
Case 7: Result = "Jul"
Case 8: Result = "Aug"
Case 9: Result = "Sep"
Case 10: result = "Oct"
Case 11: Result = "Nov"
Case 12: Result = "dec"
End select
Enmonthname = Result
End Function
%>

RSS. XML formatCopy codeThe Code is as follows: <! -- # Include file = "conn. asp" -->
<%
Strurl = "http: //" & request. servervariables ("SERVER_NAME ")&_
Left (request. servervariables ("script_name"), Len (request. servervariables ("script_name")-len ("/RSS. asp "))
Dim foolcat, JS
Set JS = server. Createobject ("ADODB. recordset ")
SQL = "select * from [Table name] Order by ID ASC"
Set JS = conn.exe cute (SQL)

Foolcat = foolcat + "<? XML version = "" 1.0 "" encoding = "" UTF-8 ""?> "
Foolcat = foolcat + "<RSS version =" "2.0" ">"
Foolcat = foolcat + "<channel>"
Foolcat = foolcat + "<title> xxx.com XML feed </title>"
Foolcat = foolcat + "<link>" & strurl & "</link>"
Foolcat = foolcat + "<language> ZH-CN </language>"
Foolcat = foolcat + "<copyright> an XML feed for xxx.com </Copyright>"
Do until Js. EOF
Foolcat = foolcat + "<item>"
Foolcat = foolcat + "<title> <! [CDATA ["& RS (" topic field ") &"]> </title>"
Foolcat = foolcat + "<description> <! [CDATA ["& RS (" topic field ") &" <br/> "& RS (" content field ") & "<br/>]> </description>"
Foolcat = foolcat + "<link>" & strurl & "/xxx. asp? Id = "& RS (" ID field ")" </link>"
Foolcat = foolcat + "<pubdate>" & RS ("time field") & "</pubdate>"
Foolcat = foolcat + "</item>"
JS. movenext
Loop
JS. Close
Set JS = nothing
Foolcat = foolcat + "</channel>"
Foolcat = foolcat + "</RSS>"
Foolcat = "" + foolcat + ""
Foolcat = "" & foolcat &""
Folderpath = server. mappath ("/")
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set fout = FSO. createtextfile (folderpath "\ RSS. xml ")
Fout. writeline foolcat
Fout. Close
Set fout = nothing
Conn. Close
Set conn = nothing
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.