1

I am trying to pull RSS feed in email and I only manage to fetch title, description & link but I couldn't able to fetch the image URL, maybe because it's enclosed within <media:content> tag. I believe there is a way to call the values within this tag as I do for the rest of it.

It would be great if you can help me get the Image URL.

Here is the feed URL - https://www.oberlo.com/blog/feed

Here is the code I use

<div>

%%[

var @xml, @isXML, @nodes, @rowCount
Set @xml = HTTPGet("https://www.oberlo.com/blog/feed", false, 0, @CallStatus)

output(concat("<br>Call Status: ", @CallStatus))

if indexOf(@xml,"<channel>") > 0 then

  set @nodes = BuildRowsetFromXML(@xml,"/rss/channel/item",0)
  set @rowCount = rowcount(@nodes)

  output(concat("<br>rowCount: ", @rowCount))


  if @rowCount > 0 then

    for @i = 1 to 5 do

      var @title
      var @description
      var @link
      var @Image

      set @nodepath = concat("/rss/channel/item[",@i,"]/")

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"title"))) > 0 then
          set @title = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"title"),0),1),'Value')
      endif

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"description"))) > 0 then
          set @description = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"description"),0),1),'Value')
      endif

      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"link"))) > 0 then
          set @link = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"link"),0),1),'Value')
      endif



      if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath, 'Image'))) > 0 then

          set @Image = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"Image"),0),1),'image/jpeg')
      endif



      ]%%


       <h4>First Title - %%=v(@title)=%%</h4>

         Description - %%=v(@description)=%%
         <br>Link - <a href="%%=redirectto(@link)=%%">%%=v(@link)=%%</a>

          <br>Image - %%=v(@Image)=%%



      %%[

    next @i

  else

   outputline(concat("<br>no items found"))

  endif

else

  outputline(concat("<br>no XML found"))

endif

]%%

</div>

1 Answer 1

4

If you're confident that the media:content node will always be an image, you could try isolating the namespace prefix (or replace it all with a custom unique name, e.g., <mediacontentimg):

Set @xml = Replace(
  HTTPGet("https://www.oberlo.com/blog/feed", false, 0, @CallStatus),
  '<media:content',
  '<media'
)

Then use the media node's url attribute (you can do this by appending "_att" to the attribute name):

if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath, 'media'))) > 0 then
  set @Image = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"media"),0),1),'url_att')
endif

You can now use the url attribute value in an img tag:

Image - <img src="%%=v(@Image)=%%">
1
  • It works perfect, thank you :)
    – Siva
    Commented Jun 28, 2019 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .