0

我会以我是一名网页设计师这一事实作为这个问题的开头,并且我正试图通过修复我们在工作中使用的这个经典 ASP RSS 解析器代码来捏造自己的方式,所以你可能能够提供的任何基本见解都是赞赏。

我遇到了这段代码的障碍。它会解析 RSS 提要,但通常只解析使用 Feedburner 的 SmartFeed 兼容性设置的提要。我需要它做的是能够解析一个简单的简 Wordpress 提要,这似乎很难做到。我的目标是增加额外的兼容性,这样这段代码在解析提要时就不会那么挑剔。

当我将一个直接的 WP 提要放入其中时,它会引发提要无效错误并返回一个错误代码 -2146697211,从查找代码来看,这似乎意味着无法找到提要。我尝试将Server.CreateObject("MSXML2.DomDocument.3.0")更改为Server.CreateObject("MSXML2.DomDocument.4.0"),但似乎我们的服务器无法处理 4.0。虽然这可能是可以升级的东西,但在此问题上获得开发时间的可能性很小。因此,如果可能的话,我将尝试使用当前的 IIS 设置使其工作。

是否有人对可以进行任何调整以使其正常工作有任何想法?谢谢。

       <%
                SUB DisplayRSSFeed(URLToRSS, MaxNumberOfItems) 


                Set fs=Server.CreateObject("Scripting.FileSystemObject")
                IF fs.FileExists(Server.MapPath(TemplatePath & "rss_template.asp")) THEN
                    Set f=fs.OpenTextFile(Server.MapPath(TemplatePath & "rss_template.asp"), 1)
                    itemTemplate = f.ReadAll
                    f.Close
                Set f=Nothing 

                ELSE

                    ' =========== configuration =====================
                    ' Item template.
                    ' {LINK} will be replaced with item link
                    ' {TITLE} will be replaced with item title
                    ' {DESCRIPTION} will be replaced with item description
                    'ItemTemplate = "<tr><td><a target='_blank' href=" & """{LINK}""" & ">{TITLE}</a><BR>{DESCRIPTION}</td></tr>"

                    ItemTemplate = ""
                    ItemTemplate = ItemTemplate & "<div class=""sp_blogPost"">"
                    ItemTemplate = ItemTemplate & "     <h2><a href=""{LINK}"" target=""_blank"">{TITLE}</a></h2>"
                    ItemTemplate = ItemTemplate & "     <h5>Posted on {DATE}</h5>"
                    ItemTemplate = ItemTemplate & "     <p>"
                    ItemTemplate = ItemTemplate & "         {DESCRIPTION}"
                    ItemTemplate = ItemTemplate & "     </p>"
                    ItemTemplate = ItemTemplate & "     <a href=""{LINK}"" target=""_blank"">Continue Reading Article</a>"
                    ItemTemplate = ItemTemplate & "</div>"
                    ItemTemplate = ItemTemplate & "<div class=""sp_blogDivider""></div>"
                    ' ================================================
                END IF 

                    On Error Resume Next
                    Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
                    xmlHttp.Open "Get", URLToRSS, false
                    IF Err.number <> 0 then
                        Response.Write "The URL is not valid"
                        Exit Sub            
                    END IF        
                    xmlHttp.Send()
                    RSSXML = xmlHttp.ResponseText

                Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
                    xmlDOM.async = false
                    xmlDOM.LoadXml(RSSXML)
                    IF Err.number <> 0 then
                        Response.Write "The RSS Data is not valid"
                        Response.Write Err.number
                        Exit Sub            
                    END IF        

                    Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS        

                    j = -1
                    FOR EACH RSSItem IN RSSItems
                    FOR EACH child IN RSSItem.childNodes
                        Select case lcase(child.nodeName)
                            case "title"
                                RSStitle = child.text
                            case "enclosure"
                                RSSimage = child.getAttribute("url")
                    ''      case "link"
                    ''          RSSlink = child.text
                            case "guid"
                                RSSlink = child.text
                            case "description"
                                RSSdescription = child.text

                                Set re = New RegExp
                                re.Pattern = "<[^>]+>"
                                re.IgnoreCase = true
                                re.Global = true

                                RSSdescription = re.Replace(RSSdescription, "")

                                set re = nothing

                                if len(RSSdescription) > 300 then RSSdescription = mid(RSSdescription, 1, 300) & "..."
                            case "pubdate"
                                RSSdate = child.text
                                RSSdate = split(RSSDate, "T")(0)
                                arrDate = split(RSSDate, "-")
                                if ubound(arrDate) = 2 then
                                    RSSdate = arrDate(1) & "." & arrDate(2) & "." & arrDate(0)
                                else
                                    RSSdate = Replace(RSSdate, "-", ".")
                                end if
                        END SELECT
                        NEXT                                     
                            j = J+1                                     
                            IF J < CInt(MaxNumberOfItems) THEN
                                Itemcontent = ItemTemplate
                                Itemcontent = Replace(Itemcontent,"{DATE}", RSSdate)
                                Itemcontent = Replace(Itemcontent,"{IMAGE}", RSSimage)
                                ItemContent = Replace(ItemContent,"{LINK}",RSSlink)
                                ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
                                ItemContent = Replace(ItemContent,"{DESCRIPTION}",RSSDescription)

                                Response.Write ItemContent
                                ItemContent = ""
                            END IF
                        NEXT
                    'Response.Write "</table>"
                    On Error GoTo 0
                END SUB
                %>
4

0 回答 0