经典的ASP RSS Parser和Wordpress Feed兼容性

时间:2012-10-31 14:08:04

标签: wordpress asp-classic rss xml-parsing

我将在这个问题上加上我是一名网页设计师的事实,我试图通过修复我们在工作中使用的经典ASP RSS解析器代码来捏造我的方式,所以任何基本的洞察力你都可以报价将不胜感激。

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

当我在其中放入一个直接的WP Feed时,它会导致Feed无效错误并返回错误代码-2146697211,从查找代码时可能意味着无法找到Feed。我尝试将 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
                %>

0 个答案:

没有答案