SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error with RSS > ASP script

    Hi,

    I've got a function which parses RSS feeds into HTML via some ASP processing:

    Code:
    function getRSSFeed(strRSSFeedURL, strSource_In)
     ' ##### URL to RSS Feed to display #########
     URLToRSS = strRSSFeedURL
     ' ##### max number of displayed items #####
     MaxNumberOfItems = 1
     ' ##### Main template constants
     MainTemplateHeader = ""
     MainTemplateFooter = ""
     ' ##### 
     ' ##### Item template.
     ' ##### {LINK} will be replaced with item link
     ' ##### {TITLE} will be replaced with item title
     ' ##### {DESCRIPTION} will be replaced with item description
     ItemTemplate = "<h2><a href=" & """{LINK}""" & " target=""_blank"">{TITLE}</a></h2><p class=""source""><strong>Source:</strong> " & strSource_In & "</p><p><a href=" & """{LINK}""" & " target=""_blank"">{DESCRIPTION}</a></p>"
     ' ##### Error message that will be displayed if not items etc
     ErrorMessage = "Error has occured while trying to process " &URLToRSS & "<BR>Please contact web-master"
     ' ================================================
     Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
     xmlHttp.Open "Get", URLToRSS, false
     xmlHttp.Send()
     RSSXML = xmlHttp.ResponseText
     
     Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
     xmlDOM.async = false
     xmlDOM.LoadXml(RSSXML)
     
     Set xmlHttp = Nothing ' clear HTTP object
     
     Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS
     Set xmlDOM = Nothing ' clear XML
     
     RSSItemsCount = RSSItems.Length-1
      
     j = -1
     
     For i = 0 To RSSItemsCount
     Set RSSItem = RSSItems.Item(i)
     
      for each child in RSSItem.childNodes
       Select case lcase(child.nodeName)
         case "title"
               RSStitle = child.text
         case "link"
               RSSlink = child.text
         case "description"
               RSSdescription = child.text
       End Select
      next
     
      j = J+1
     
      RSSdescription = WholeWords(RSSdescription,80)
     
      if J<MaxNumberOfItems then 
      ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
      ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
      Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription)
      ItemContent = ""
      End if
     
     Next 
     'Response.End ' uncomment this line if you need to finalize output
    end function
    Sometimes this works perfectly, but most of the time I get an error:

    Code:
    Microsoft VBScript runtime error '800a01fb' 
    
    An exception occurred: 'xmlHttp.Send' 
    
    news.asp, line 51
    Can anyone see why this might be happening, and more importantly how to get it working properly all the time?

    Thanks very much...

  2. #2
    SitePoint Member
    Join Date
    Jul 2005
    Location
    South Carolina
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't done a lot with xmlHTTP, but there are couple of things you could look at.

    First would be is URLToRSS getting set to a value everytime.

    Second, could the xmlHttp.Send() operation be returning empty.

    I am wondering if you put an On Error Resume Next before the xmlHTTP code if you would get something back in the xmlHttp.ResponseText that might be of help. Of course it could just come back blank.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following instead :-

    Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
    Set xmlDOM = Server.CreateObject("Microsoft.XMLDOM")

  4. #4
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, this seems to get rid of the error, but now only one of my news feeds seems to be picked up.

    I can't believe how flaky this is - ASP and RSS is a very poor combination IMHO. I can't be learning PHP just to do this though. Ahhhrrgggh!

    Does anyone have a sample ASP script which reliably displays RSS feeds from several different sources - showing headline, source and first few words of the article, or is there no such thing?

    Thanks

  5. #5
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just for the record, I've ditched the ASP method, and opted for a much less customisable yet more robust (i.e. it works) method of using Javascript from here:

    http://www.globalsyndication.com/rss-to-javascript

  6. #6
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why ditch the ASP method? The globalsyndication route is still server side (on their server) and just uses the javascript to display it to your users. It still means that you rely on their server and whatever it chooses to spit out. What happens when their server is under pressure or down? What happens if they decide to brand it?

    By doing it on your own server you can cache the feeds locally to conserve resources, filter ads, etc.

    See this site for starters. http://netnerds.net/archive/2004/11/17/332.aspx

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    ca
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    free working example of rss consumption by asp http://www.ecommercemax.com/rss_howto.asp

  8. #8
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ole dawg
    Thanks for the link. Someone clicked it today but the posting has moved:

    http://blog.netnerds.net/2006/04/eas...n-classic-asp/
    The code is basically this.. (and works right out the box)
    Code:
     
    <%
    Call getNews(10)
     
    Sub getNEWS(howManyResults)
    myRSSfile = "http://rss.news.yahoo.com/rss/tech"
     
    Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.4.0")
    xmlHttp.Open "Get", myRSSfile, false
    xmlHttp.Send()
    myXML = xmlHttp.ResponseText
     
    Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
    xmlResponse.async = false
    xmlResponse.LoadXml(myXML)
    Set xmlHttp = Nothing
     
    Set objLst = xmlResponse.getElementsByTagName("item")
    Set xmlResponse = Nothing
     
    intNoOfHeadlines = objLst.length -1
     
    For i = 0 To (intNoOfHeadlines)
    Set     objHdl = objLst.item(i)
     
    for each child in objHdl.childNodes
    Select case lcase(child.nodeName)
        case "title"
              title = child.text
        case "link"
              link = child.text
        case "description"
              description = child.text
         'You can also use the following: author,category,comments,enclosure,guid,pubDate,source
    End Select
    next
     
       kk = kk+1  
         if kk < howManyresults+1 then
        Response.Write "<br /><a href=""" & link & """>" & title & "</a> <br> " & description
     
        end if
     
    Next
    End Sub
    %>

  9. #9
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    did not work for me

    Server object error 'ASP 0177 : 800401f3'

    Server.CreateObject Failed

    /test2.asp, line 7

    Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.

  10. #10
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Kentucky USA
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this... I changed the bolded line... works ok for me. personnaly I use the routine as the opening post.

    Code:
    <%
    Call getNews(10)
     
    Sub getNEWS(howManyResults)
    myRSSfile = "http://rss.news.yahoo.com/rss/tech"
     
    Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xmlHttp.Open "Get", myRSSfile, false
    xmlHttp.Send()
    myXML = xmlHttp.ResponseText
     
    Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
    xmlResponse.async = false
    xmlResponse.LoadXml(myXML)
    Set xmlHttp = Nothing
     
    Set objLst = xmlResponse.getElementsByTagName("item")
    Set xmlResponse = Nothing
     
    intNoOfHeadlines = objLst.length -1
     
    For i = 0 To (intNoOfHeadlines)
    Set     objHdl = objLst.item(i)
     
    for each child in objHdl.childNodes
    Select case lcase(child.nodeName)
        case "title"
              title = child.text
        case "link"
              link = child.text
        case "description"
              description = child.text
         'You can also use the following: author,category,comments,enclosure,guid,pubDate,source
    End Select
    next
     
       kk = kk+1  
         if kk < howManyresults+1 then
        Response.Write "<br /><a href=""" & link & """>" & title & "</a> <br> " & description
     
        end if
     
    Next
    End Sub
    %>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •