虽然将.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
……
闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁惧墽鎳撻—鍐偓锝庝簼閹癸綁鏌i鐐搭棞闁靛棙甯掗~婵嬫晲閸涱剙顥氬┑掳鍊楁慨鐑藉磻閻愮儤鍋嬮柣妯荤湽閳ь兛绶氬鎾閳╁啯鐝曢梻浣藉Г閿氭い锔诲枤缁辨棃寮撮悢铏圭槇闂佹眹鍨藉ḿ褍鐡梻浣瑰濞插繘宕愬┑瀣畺鐟滄柨鐣烽崡鐐╂瀻闁瑰濮烽崝鍫曟⒒娴gǹ顥忛柛瀣瀹曚即骞橀崜浣风瑝婵°倧绲介崯顖炴偂濞嗘挻鍊垫繛鎴炵憽缂傛岸鏌熼崘鎻掓殻闁哄矉缍€缁犳盯鏁愰崟顖氫粣闂備礁鎼張顒傜矙閹捐鐒垫い鎺戯功缁夌敻鏌涢幘瀵告噰鐎殿喚枪閳藉濮€閿涘嫬骞愰柣搴″帨閸嬫捇鎮楅敐搴″鐞氾箑鈹戦悩娈挎毌闁逞屽墮绾绢參宕洪敐鍥e亾鐟欏嫭澶勫ù婊勭箞楠炲繘宕ㄩ娑樻瀭闂佸憡娲﹂崜娑溿亹瀹勫棗鈹戦悩鍨毄濠殿喚鍏樺顐﹀川婵犲啫寮块梺缁樺灱濡嫰寮告笟鈧弻鐔兼⒒鐎靛壊妲紒鐐劤椤兘寮婚敐澶婄疀妞ゆ帊鐒﹂崕鎾绘⒑閹肩偛濡奸柛濠傛健瀵鈽夐姀鈺傛櫇闂佹寧绻傚Λ娑⑺囬妷褏纾藉ù锝呮惈灏忛梺鍛婎殕婵炲﹤顕f繝姘亜闁稿繐鐨烽幏濠氭煟鎼达紕浠涢柣鈩冩礈缁絽螖閸涱喒鎷洪柡澶屽仦婢瑰棝藝閿曞倹鍊垫慨姗嗗亜瀹撳棛鈧鍠涢褔鍩ユ径鎰潊闁冲搫鍊瑰▍鍥⒒娴g懓顕滅紒璇插€哥叅闁冲搫鍟伴惌姘舵煕瑜庨〃鍡涘磻閳╁啰绡€濠电姴鍊归崳瑙勩亜閿濆懌鍋㈤柟顔荤矙椤㈡稑鈽夋潏銊ф澒闁诲孩顔栭崰妤呮偂閿熺姷宓侀柡宥冨妽婵挳鏌涢敂璇插箹鐎殿喗濞婂缁樻媴閾忕懓绗″┑鐐插级閻楃姴鐣烽幇鏉挎嵍妞ゆ挻绋戞禍鐐叏濡厧浜鹃悗姘炬嫹