欢迎光临
我们一直在努力

读取符合RSS2.0规范的XML文档-ASP教程,XML相关

建站超值云服务器,限时71元/月

想试着做一个简单的读取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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 读取符合RSS2.0规范的XML文档-ASP教程,XML相关
分享到: 更多 (0)

相关推荐

  • 暂无文章