想試著做一個簡單的讀取RSS新聞的頁面 雖然將.net中關于XML的幾個類看了個遍但還是不太懂這是我寫的一個讀取XML文檔的函數直接在設計頁面中調用就行 Public Function LoadRSS(ByVal RssUrl As String, ByVal showNewsCount As Integer) As String Try '讀取xml文檔 Dim objXMLDoc As New System.Xml.XmlDocument() Dim strNodes As String = "" Dim objItems As System.Xml.XmlNodeList Dim objItems1 As System.Xml.XmlNodeList Dim objNode As System.Xml.XmlNode Dim objNode1 As System.Xml.XmlNode Dim i As Integer Dim newsTitle As String Dim newsUrl As String Dim newsDescription As String Dim newsPubDate As String Dim newsAuthor As String Dim newsCategory As String objXMLDoc.Load(RssUrl) objItems = objXMLDoc.GetElementsByTagName("item") If RssUrl = "" Then RSSNews = "未找到信息源,您可刷新重試或聯系管理員!" Exit Function End If If CStr(showNewsCount) = "" Or showNewsCount > 30 Then showNewsCount = 10 '默認新聞顯示數目 End If If showNewsCount = 0 Then showNewsCount = objItems.Count End If If objXMLDoc.HasChildNodes = True Then i = 1 For Each objNode In objItems If objNode.HasChildNodes = True Then objItems1 = objNode.ChildNodes For Each objNode1 In objItems1 Select Case objNode1.Name Case "title" newsTitle = objNode1.InnerText Case "link" newsUrl = objNode1.InnerText Case "description" newsDescription = objNode1.InnerText If Len(newsDescription) > 500 Then newsDescription = Left(newsDescription, 200) End If newsDescription = FilterHtml(newsDescription) Case "category" newsCategory = objNode1.InnerText Case "author" newsAuthor = objNode1.InnerText Case "pubDate" newsPubDate = objNode1.InnerText End Select Next strNodes += "<a href=viewnews.aspx?newstitle=" & Server.UrlEncode(newsTitle) & "&newsurl=" & Server.UrlEncode(newsUrl) & _ "&newsdscrp=" & Server.UrlEncode(newsDescription) & "&newscat=" & Server.UrlEncode(newsCategory) & _ "&newsauthor=" & Server.UrlEncode(newsAuthor) & "&newsdate=" & Server.UrlEncode(newsPubDate) & _ " target=_blank>" & newsTitle & "</a><br>" End If i = i + 1 If i > showNewsCount Then Exit For Next End If LoadRSS = strNodes Catch objErr As Exception LoadRSS = "RSS Feed 源數據出錯!" End Try End Function
雖然將.net中關于XML的幾個類看了個遍
但還是不太懂
這是我寫的一個讀取XML文檔的函數
直接在設計頁面中調用就行
Public Function LoadRSS(ByVal RssUrl As String, ByVal showNewsCount As Integer) As String
Try
'讀取xml文檔 Dim objXMLDoc As New System.Xml.XmlDocument() Dim strNodes As String = "" Dim objItems As System.Xml.XmlNodeList Dim objItems1 As System.Xml.XmlNodeList Dim objNode As System.Xml.XmlNode Dim objNode1 As System.Xml.XmlNode Dim i As Integer Dim newsTitle As String Dim newsUrl As String Dim newsDescription As String Dim newsPubDate As String Dim newsAuthor As String Dim newsCategory As String
objXMLDoc.Load(RssUrl)
objItems = objXMLDoc.GetElementsByTagName("item")
If RssUrl = "" Then RSSNews = "未找到信息源,您可刷新重試或聯系管理員!" Exit Function End If
If CStr(showNewsCount) = "" Or showNewsCount > 30 Then showNewsCount = 10 '默認新聞顯示數目 End If
If showNewsCount = 0 Then showNewsCount = objItems.Count End If
If objXMLDoc.HasChildNodes = True Then i = 1 For Each objNode In objItems
If objNode.HasChildNodes = True Then objItems1 = objNode.ChildNodes For Each objNode1 In objItems1
Select Case objNode1.Name Case "title" newsTitle = objNode1.InnerText Case "link" newsUrl = objNode1.InnerText Case "description" newsDescription = objNode1.InnerText If Len(newsDescription) > 500 Then newsDescription = Left(newsDescription, 200) End If newsDescription = FilterHtml(newsDescription) Case "category" newsCategory = objNode1.InnerText Case "author" newsAuthor = objNode1.InnerText Case "pubDate" newsPubDate = objNode1.InnerText End Select
Next strNodes += "<a href=viewnews.aspx?newstitle=" & Server.UrlEncode(newsTitle) & "&newsurl=" & Server.UrlEncode(newsUrl) & _ "&newsdscrp=" & Server.UrlEncode(newsDescription) & "&newscat=" & Server.UrlEncode(newsCategory) & _ "&newsauthor=" & Server.UrlEncode(newsAuthor) & "&newsdate=" & Server.UrlEncode(newsPubDate) & _ " target=_blank>" & newsTitle & "</a><br>" End If i = i + 1 If i > showNewsCount Then Exit For Next End If
LoadRSS = strNodes Catch objErr As Exception LoadRSS = "RSS Feed 源數據出錯!"
End Try
End Function
溫馨提示:喜歡本站的話,請收藏一下本站!
本站發布的Win7純凈版系統、Win10純凈版和XP純凈版系統僅為個人學習測試使用,請在下載后24小時內刪除,不得用于任何商業用途,否則后果自負,請支持購買微軟正版軟件!
本站所有資源全部來自于網絡資源,如侵犯到您的權益,請及時通知我們(),我們會及時處理.
Copyright © 2018-2020 蘿卜系統下載站 手機站 關于本站