Daily Archives: 2006/12/05

[ASP.NET][VB2005]一個簡單的 RSS Reader 實做


 
輸入目標 rss 位置,若是沒有位置可輸入,可測試:http://www.tlcheng.tk/News/rss2.aspx?Newsgroup=tw.bbs.comp.lang.basic&Action=List
 
主要程式碼摘錄如下:

 Sub Main()
  If ((request(“REQUEST_METHOD") = “POST") and (request(“CONTENT_LENGTH") > 0)) then
   Dim strRssUrl As String = Request(“txtInput")
   Dim ibc, ibr As Integer
   Dim wc As New System.Net.WebClient
   Dim rssDoc As New System.Xml.XmlDocument
   Dim rssList As System.Xml.XmlNodeList
   Dim ms As New IO.MemoryStream(wc.DownloadData(strRssUrl))
   Dim strXml, strName As String

   rssDoc.Load(ms)   
   rssList = rssDoc.GetElementsByTagName(“item")

   Response.Write(“<table width=’100%’>" & vbNewLine)
   For ibc = 0 To rssList.Count – 1
    With rssList(ibc)
     For ibr = 0 To .ChildNodes.Count – 1
      With .ChildNodes(ibr)
       strName = .Name.ToString()
       strXml = .InnerXml
       Select Case LCase(strName)
        Case “link", “guid", “comments"
         strXml = “<a href='" & strXml & “‘>" & strXml & “</a>"
        Case “author"
         strXml = “<a href=’mailto:" & strXml & “‘>" & strXml & “</a>"

        Case Else
         strXml = Replace(strXml, “&lt;", “<“)
         strXml = Replace(strXml, “&gt;", “>")
         strXml = Replace(strXml, “&amp;", “&")
       End Select
       Response.Write(“<tr><th>" & strName & “</th><td>" & strXml & “</td>" & vbNewLine)
      End With
     Next
     ‘Debug.WriteLine(.Item(“title").InnerText & “(" & .Item(“pubDate").InnerText & “)")
    End With
   Next
   Response.Write(“</table>" & vbNewLine)
  End If
 End Sub
廣告
Categories: 技術分享 | 發表留言

在WordPress.com寫網誌.

%d 位部落客按了讚: