|
|
#1 (permalink) |
|
Üyelik Tarihi: 13.07.2000
Yer: LND
Mesaj: 4,251
|
ASP ile RSS Yayınlama Örneği
Bu soru çok klasik ve çok fazla karşılaşıyorum mantık çok basit bende burada kendi sitemde kullandığım kodu yayınlamak istedim (tam olarak böyle değil ama aynı mantık),
İlk önemli nokta browser' ın .ASP uzantısına rağmen sayfayı XML olarak yorumlaması gerektiği; Sayfanın başına bunu koymamız yeterli, Kod:
Response.ContentType="application/XML"
Kod:
<% IntPageSize = 15 RsNewsSQL = "SELECT TOP 15 id, baslik, makale, tarih FROM makaleler ORDER BY id DESC" Set RsNews = server.CreateObject("ADODB.Recordset") RsNews.ActiveConnection = conn RsNews.Source = RsNewsSQL RsNews.CursorType = 1 RsNews.CursorLocation = 2 RsNews.LockType = 1 RsNews.Open() %> <?XML version="1.0" encoding="iso-8859-9"?> <RSS version="2.0"> <channel> <title>Ferruh Mavituna | Articles</title> <link>http://ferruh.mavituna.com</link> <description>Ferruh Mavituna tarafından yazılan güvenlik, web teknolojileri başta olmak üzere çeşitli konuları kapsayan makaleler ve haberler.</description> <language>tr</language> <copyright>Copyright 1997-2003 Ferruh Mavituna</copyright> <lastBuildDate><%=GetRFC822Date(RsNews("Tarih"))%></lastBuildDate> <docs>http://backend.userland.com/RSS</docs> <generator>Ferruh Mavituna ASP - RSS</generator> <managingEditor>ferruh-at-mavituna.com</managingEditor> <webMaster>ferruh-at-mavituna.com</webMaster> <ttl>60</ttl> <image> <title>Ferruh Mavituna</title> <url>http://ferruh.mavituna.com/RSS/RSS.gif</url> <link>http://ferruh.mavituna.com</link> </image> <% While Not RsNews.EOF Makale = RsNews("makale") Makale = fm_GoodLinks(DbNews) 'Fix RSS Makale = Replace(Xstr," src=""/"," src=""http://ferruh.mavituna.com/") Makale = server.HTMLEncode(Xstr) Baslik = server.HTMLEncode(RsNews("Baslik")) Response.Write "<item>" & vbNewline &_ "<title>" & Baslik &"</title>" & vbNewline &_ "<pubDate>" & GetRFC822Date(RsNews("Tarih")) & "</pubDate>" & vbNewline &_ "<link>http://ferruh.mavituna.com/article/?" & RsNews("ID") & "</link>" & vbNewline &_ "<description>" & Makale & "</description>" & vbNewline &_ "</item>" RsNews.MoveNext Wend RsNews.Close Set RsNews = Nothing %> </channel> </RSS> RSS Tarih standartı için şu fnksiyonları da ekleyin (kodun yazarı : ' [tempus_rook@Hotmail.com 2003-11-02] Code written.) Kod:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' GetRFC822Date ' Purpose: ' Gets date in the RFC 822 format (with 4-digit year) as required by the RSS ' 2.0 spec. ' Parameters: ' dtmDate - Date to format. ' Returns: ' Formatted date. ' Revisions: ' [tempus_rook@Hotmail.com 2003-11-02] Code written. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function GetRFC822Date(dtmDate) ' XXX what about daylight savings? Dim strDate strDate = Left(WeekdayName(DatePart("w", dtmDate)), 3) & ", " & _ LeadingZero(DatePart("d", dtmDate)) strDate = strDate & _ " " & Left(MonthName(DatePart("m", dtmDate)), 3) & " " & _ DatePart("yyyy", dtmDate) & _ " " & LeadingZero(DatePart("h", dtmDate)) strDate = strDate & ":" & LeadingZero(DatePart("n", dtmDate)) & _ ":" & LeadingZero(DatePart("s", dtmDate)) & " GMT" GetRFC822Date = strDate ' Format: Sun, 02 Nov 2003 13:40:01 GMT End Function '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' LeadingZero ' Purpose: ' Adds a leading zero to single digit numbers. ' Parameters: ' strText - Var to add a zero to, if necessary. ' Returns: ' Original text, with leading zero if required. ' Revisions: ' [tempus_rook@Hotmail.com 2003-11-02] Code written. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function LeadingZero(strText) If Len(strText) = 1 Then LeadingZero = "0" & strText Else LeadingZero = strText End If End Function |
|
|
|
Zoque'a hoşgeldiniz!