1

I am embedding an RSS feed in an email using AMPScript. I am successfully pulling in the title, description and link, but I’d also like to include the image that’s part of the description in the feed. However, I cannot figure out the syntax to use, as the image is wrapped in a CDATA tag

Here is the link to the RSS feed I am using: http://rssfeeds.militarytimes.com/militarytimes/newsletters/roundup&x=1

It also lists the image url in an enclosure tag with a url= but I not sure how I would need to grab that either.

The code I am using in the email is:

%%[Var @xml, @titles, @title, @descs, @desc, @links, @link, @images, @image, @cnt
Set @xml = ContentAreaByName("my contents\RSSParse-MilitaryTimes-DailyRoundup")
Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
Set @images = BuildRowsetFromXML(@xml,"//item/enclosure",1)

Set @rows = RowCount(@titles)

IF @rows >= 1 THEN
for @cnt = 1 to @rows do
Set @title = Field(Row(@titles,@cnt),"Value")
Set @desc = Field(Row(@descs,@cnt), "Value")
Set @link = Field(Row(@links,@cnt), "Value") 
Set @image = Field(Row(@images,@cnt), "Value")]%%
<table>
    <tr>
        <td>%%=v(@image)=%%</td>
   </tr>
    <tr>
        <td>%%=v(@title)=%%</td>
   </tr>
    <tr>
        <td>%%=v(@desc)=%%</td>
    </tr>
    <tr>
        <td><a href="%%=RedirectTo(@link">Read More</a></td>
    </tr>
</table>
%%[
    NEXT @cnt
    ENDIF
   ]%%

Can anyone help?

1
  • Your RedirectTo call is incomplete and should read "%%=RedirectTo(@link)=%%" . Is that typo in your main code? – Timothy Nov 7 '14 at 17:02
0

You could just parse the image URL from description node like this:

%%[

 var @desc, @temp, @image
 set @desc = 'extra text here <img border="0" style="max-width:100%" src="http://www.gannett-cdn.com/-mm-/e1256297e1227e7964c701fecfef8825a86edefe/r=916x200/local/-/media/GGM/None/2014/10/16/635490534337074523-hov-bgillustration-logo-920a.jpg"/> more extra text'

 /* trim the beginning */
 set @temp = substring(@desc,add(indexOf(@desc,"src="),5),length(@desc))

 /* trim the end */  
 set @image = substring(@temp,1,subtract(indexOf(@temp,'"'),1))  

]%%

%%=v(@image)=%%<br><br>

That results in this:

http://www.gannett-cdn.com/-mm-/e1256297e1227e7964c701fecfef8825a86edefe/r=916x200/local/-/media/GGM/None/2014/10/16/635490534337074523-hov-bgillustration-logo-920a.jpg

For more information

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.