Displaying an image from RSS Enclosure tag with ASP

Hi People - I've been killing myself trying to solve this problem. The news feed that use on our website now gives images as part of it's feed. Only trouble is I don't know how to display the URL attribute in the <enclosure> tag.

Any help is appreciated.


<%
 Response.Expires = -1
 
 ' ##### URL to RSS Feed to display #########
 URLToRSS = "http://feeds.news.com.au/public/rss/2.0/news_the_nation_45.xml"
 
 ' ##### max number of displayed items #####
 MaxNumberOfItems = 1
 
 ' ##### Main template constants
 MainTemplateHeader = "<table>"
 MainTemplateFooter = "</table>"
 
 Keyword1 =  ""  ' Keyword1 =  "tech" - set non-empty keyword value to filter by this keyword
 Keyword2 = "" ' Keyword1 =  "win" - set non-empty keyword value to filter by this keyword
' #################################
 
 ' ##### Item template.
 ' ##### {LINK} will be replaced with item link
 ' ##### {TITLE} will be replaced with item title
 ' ##### {DESCRIPTION} will be replaced with item description
  '##### {ENCLOSURE_URL} will be replaced with Media URL
' ##### {ENCLOSURE_TYPE} will be replaced with Media title
' ##### {ENCLOSURE_SIZE} will be replaced with Media file size in KB
 ItemTemplate = "<tr><td><a href=" & """{LINK}""" & "target='_blank'><b><font size=3>{TITLE}</font></b></a><img src=" & "{ENCLOSURE_URL}" & "><BR>{DESCRIPTION}{ENCLOSURE_URL}</td></tr>"
 
 ' ##### 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
 
 ' writing Header
 if RSSItemsCount > 0 then 
  Response.Write MainTemplateHeader
 End If
 
 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
     case "enclosure"
           RSSenclosure =  child.text
	 case "enclosure_url"
           RSSenclosure_url =  child.text
	 case "enclosure_type"
           RSSenclosure_type =  at.text
   End Select
  next
 
' now check filter
 If (InStr(RSSTitle,Keyword1)>0) or (InStr(RSSTitle,Keyword2)>0) or (InStr(RSSDescription,Keyword1)>0) or (InStr(RSSDescription,Keyword2)>0) then
 
  j = J+1
 
  if J<MaxNumberOfItems then 
  ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
  ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
  ItemContent = Replace(ItemContent,"{ENCLOSURE}",RSSenclosure)  
   ItemContent = Replace(ItemContent,"{ENCLOSURE_URL}",RSSenclosure_url)   
  Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription)
 
  ItemContent = ""
  End if
End If 
 
 Next
 
 ' writing Footer
 if RSSItemsCount > 0 then 
  Response.Write MainTemplateFooter
 else 
  Response.Write ErrorMessage
 End If
 
' Response.End
%>

Open in new window

MrBigJustAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
...
     case "enclosure"
           RSSenclosure =  child.text
           RSSenclosureURL = child.getAttribute("url")
...
MrBigJustAuthor Commented:
Hi Heilo,

unfortunately that doesn't seem to work
Ray PaseurCommented:
Here is a copy of my RSS feed that includes an image for the channel, but not for the individual items.  It does not have an "enclosure" tag - it has an "image" tag with a URL.  The main difference seems to be that the enclosure tag will be turned into an array, whereas the image tag will be part of the object

Both Yours and Mine with image tag:
rss->channel->image->url

Yours with enclosure tag:
rss->channel->item->enclosure[type] =
rss->channel->item->enclosure[length] =
rss->channel->item->enclosure[url] =

I'm not ver good with VB, but maybe this will help you.  Best, ~Ray
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<!-- -->
<!-- -->
<!--     IF YOU CAN SEE THIS, YOU NEED AN RSS READER!   -->
<!-- -->
<!-- -->
<channel>
  <title>National Trust Community Investment Corporation News</title>
  <link>http://www.NTCICFunds.com/</link>
  <description>NTCIC makes equity investments in real estate projects that qualify for historic tax credits.</description>
  <language>en-us</language>
  <pubDate>Tue, 26 Aug 2008 13:00:01 CDT</pubDate>
  
  <image>
    <url>http://NTCICFunds.com/images/ntcic_rss_logo.png</url>
    <title>NTCIC Web Site</title>
    <link>http://www.NTCICFunds.com/</link>
  </image>
  
  <item>
    <title>NTCIC News Updated on Tue, 26 Aug 2008 13:00:01 CDT!</title>
    <link>http://www.NTCICFunds.com/news/</link>
    <description>The RSS Feed from www.NTCICFunds.com has been updated.</description>
    <pubDate>Tue, 26 Aug 2008 13:00:01 CDT</pubDate>
  </item>
  
</channel>
</rss>

Open in new window

hieloCommented:
I think this is what you want:
...
  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
     case "enclosure"
           RSSenclosure =  child.text
	 'case "enclosure_url"
           RSSenclosure_url =  child.getAttribute("url")
	 case "enclosure_type"
           RSSenclosure_type =  at.text
   End Select
  next
...

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MrBigJustAuthor Commented:
Thanks Heilo!! Worked a dream!! You're a legend!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.