ASP ile RSS Yapmak

Really Simple Syndication

RSS Nedir?
RSS (Rich Site Summary / Really Simple Syndication) sitelerin içeriklerini başlıklar şeklinde sunmak için kullanılan bir teknoloji. Temelinde bir XML dosyası yatar. Bu teknoloji ilk olarak 1999 yılında Netspace tarafından geliştirilmiştir.

Dosya Yapısı:

XML:
  1. <rss version="2.0">
  2. <channel>
  3. <title>Site Basligi</title>
  4. <link>http://www.siteninadresi.com</link>
  5. <description>Siteyle ilgili kisa açiklama</description>
  6. <language>RSS'in yayinlandigi dil kodu. Tükçe için tr</language>
  7. <item>
  8. <title>Ilk Içerigin Basligi</title>
  9. <link>Ilk Içerigin Adresi</link>
  10. <description>Ilk Içerigin Metni</description>
  11. </item>
  12. <item>
  13. <title>Ikinci Içerigin Basligi</title>
  14. <link>Ikinci Içerigin Adresi</link>
  15. <description>Ikinci Içerigin Metni</description>
  16. </item>
  17. </channel>
  18. </rss>


Sitenizden RSS Beslemesi Yayını Yapmak/Siteye RSS Eklemek

ASP:
  1. <?xml version="1.0" encoding="windows-1254" ?>
  2. <%
  3. Response.Buffer = True
  4. Response.ContentType = "text/xml" %>
  5.  
  6. Set adoCon = Server.CreateObject("ADODB.Connection")
  7. adoCon.Open = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("veritabani.mdb")
  8.  
  9. Function Temizle(strInput)
  10.     strInput = Replace(strInput,"&", "&amp;", 1, -1, 1)
  11.     strInput = Replace(strInput,"'", "'", 1, -1, 1)
  12.     strInput = Replace(strInput,"""", "", 1, -1, 1)
  13.     strInput = Replace(strInput, ">", "&gt;", 1, -1, 1)
  14.     strInput = Replace(strInput,"<","&lt;", 1, -1, 1)
  15. Temizle = strInput
  16. End Function
  17. %>
  18. <rss version="2.0">
  19. <channel>
  20. <title>mydesign.gen.tr</title>
  21. <link>http://www.mydesign.gen.tr</link>
  22. <description>En Yeni İçerikler</description>
  23. <language>tr</language>
  24. <%
  25. Set rs = Server.CreateObject("Adodb.Recordset")
  26. SQL = "SELECT * FROM tablo ORDER BY tarih DESC"
  27. rs.Open SQL, adoCon, 1, 3
  28.  
  29. i = 0
  30. Do While not rs.EOF and i <10
  31.  
  32. response.write("<item>")
  33. response.write("<title>" & Temizle(rs("baslik")) & "</title>")
  34. response.write("<link>http://www.mydesign.gen.tr/"& rs("id") &".html</link>")
  35. response.write("<description>" & Temizle(rs("ozet")) & "</description>")
  36. response.write("</item>")
  37. i = i + 1
  38.  
  39. rs.MoveNext
  40. Loop
  41.  
  42. rs.Close
  43. set rs = Nothing
  44. %>
  45. </channel>
  46. </rss>

Aslında bu kodlar bir XML dosyası yerine XML çıktısı veren bir asp sayfasının kodlarını olusturur. Peki neden bir asp sayfası çıkarıyoruz? Bunun 2 nedeni var:

  1. Eger sitenize sonradan bir RSS desteği ekleyecek olursanız, aynı zamanda bir XML dosyasında yazmanız gerekeceğinden sitenizin tüm sistemini değiştirmeniz gerekecekti.
  2. Hem sitenizin veritabanı hem de bir XML dosyasına kaydetmeniz gerekeceğinden kayıt işlemi yavaşlayacakti.

Başka Sitelerin RSS Kaynaklarından Veri Çekmek

ASP:
  1. <%@ Language="VBScript" %>
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="EN">
  6. <head>
  7. <title>[ D 0 G M A ]</title>
  8. </head>
  9. <body>
  10. <table cellpadding="0" cellspacing="0" border="0">
  11. <tr>
  12. <td>
  13. <%
  14. Dim objXML
  15. Dim objItemList
  16. Dim objItem
  17. Dim I
  18.  
  19. Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
  20. objXML.async = False
  21.  
  22. objXML.setProperty "ServerHTTPRequest", True
  23. objXML.Load("http://www.mydesign.gen.tr/rss.asp")
  24.  
  25. If objXML.parseError.errorCode <> 0 Then
  26. Response.Write "<strong>Hata:</strong> " & objXML.parseError.reason &"<br>"
  27. Response.Write "<strong>Satır:</strong> " & objXML.parseError.line &"<br>"
  28. Response.Write "<strong>Açıklama:</strong> " & Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
  29. End If
  30.  
  31. Set objItemList = objXML.getElementsByTagName("item")
  32. Set objXML = Nothing
  33.  
  34. For Each objItem In objItemList
  35. i = 1
  36. Response.Write "<div style=""padding-top:2px""><a href=""" & objItem.childNodes(1).text & """ target=""_blank"" title=""" & objItem.childNodes(2).text & """>"
  37. Response.Write "" & objItem.childNodes(0).text & "</a><br>" & vbCrLf
  38. Next
  39.  
  40. Set objItemList = Nothing
  41. %>
  42. </td>
  43. </tr>
  44. </table>
  45. </body>
  46. </html>

Makale
http://www.mydesign.gen.tr/

Yararlanılan Kaynaklar
http://www.megatokyo.com/rss
http://www.tengiz.net/dokuman/web/rss_nasil.html

You can leave a response, or trackback from your own site. Yorum yapabilirsiniz, veya kendi sitenizden geri izleme yapabilirsiniz.

Bir yorum yazın

Yorum yaparken sadece bu XHTML kodlarını kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Kapat
E-posta ile paylaş