0

I am trying to pull images into my email from our RSS feed (after installing the 'Send Images to RSS' wordpress plug in) but I keep getting this error:

Invalid index (parameter 2) passed to Row function. Index must be less than or equal to the row count.
Index Value: 1
Row Count: 0
Function: Row(@images,@cnt)

I have no idea how to fix this.

Here is the important part:

%%[Var @xml, @titles, @title, @descs, @desc, @links, @link, @cnt, @images, @image
Set @xml = HTTPGet("http://hotelmanager-blog.trivago.com/feed/email")
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/img",1)


If RowCount(@titles) > 5 THEN
SET @rows = 5
ELSE
SET @rows = RowCount(@titles)
ENDIF


IF @rows >= 1 THEN
for @cnt = 1 to @rows do
Set @title = Field(Row(@titles,@cnt),"Value")
Set @link = Field(Row(@links,@cnt), "Value") 
Set @desc = Field(Row(@descs,@cnt), "Value")
Set @image = Field(Row(@images,@cnt), "url_att")

]%%

1 Answer 1

0

Your XPATH of //item/img is expecting there to be an img node -- on the same level as title and description. Since it doesn't exist in your XML, it can't retrieve it. That's why you're getting an error.

You can code it more defensively by checking the rowcount() for every node could be missing.

Here's what I typically do (updated your your feed):

%%[

set @xml = httpget("http://hotelmanager-blog.trivago.com/feed/email")

var @i, @maxToDisplay, @nodes, @rowCount

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

set @maxToDisplay = 5

set @rowCount = iif(@rowCount > @maxToDisplay, @maxToDisplay, @rowCount)

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    var @title
    var @pubDate
    var @categoryNodes
    var @categories
    var @link
    var @image

    set @title = Field(Row(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/title"),0),1),'Value')
    set @pubDate = Field(Row(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/pubDate"),0),1),'Value')
    set @link = Field(Row(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/link"),0),1),'Value')

    if rowcount(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/image"),0)) > 0 then
      set @image = Field(Row(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/image"),0),1),'Value')
    endif

    set @categoryNodes = BuildRowsetFromXML(@xml,concat("//item[",@i,"]/category"),0)
    set @categories = rowcount(@categoryNodes)

    if not empty(@title) then

         outputline(concat("<br><br>Title: ", @title))
         outputline(concat("<br>PubDate: ", FormatDate(@pubDate, "MMM DD, YYYY hh:MM tt")))
         outputline(concat("<br>link: ", @link))
         outputline(concat("<br>image: ", @image))
         outputline(concat("<br>categories: ", @categories))

         var @j
         var @category

         for @j = 1 to @categories do

          set @category = Field(row(BuildRowsetFromXML(@xml,concat("//item[",@i,"]/category[",@j,"]"),0),1),"Value")
          outputline(concat("<br>category ", @j ,": ", @category))

         next @j

    endif

  next @i

else

  raiseerror("no articles found")

endif

]%% 

Output

Title: The Future of Luxury Travel & Hospitality at ITB Berlin 
PubDate: Mar 10, 2017 03:03 PM 
link: http://hotelmanager-blog.trivago.com/future-luxury-travel-hospitality/ 
image: 
categories: 2 
category 1: Discover Industry Highlights 
category 2: Feature 

Title: Metasearch Helps Hoteliers Drive Direct Bookings 
PubDate: Mar 10, 2017 02:03 AM 
link: http://hotelmanager-blog.trivago.com/metasearch-helps-hoteliers-drive-direct-bookings/ 
image: 
categories: 6 
category 1: Discover Industry Highlights 
category 2: Uncategorized 
category 3: Events & Webinar 
category 4: Feature 
category 5: Hotel Metasearch Marketing Tips 
category 6: Hotel technology 

Title: The Future of Travel Comes to Life at ITB Berlin 2017 
PubDate: Mar 08, 2017 12:03 PM 
link: http://hotelmanager-blog.trivago.com/future-of-travel-itb-berlin-2017/ 
image: 
categories: 6 
category 1: Discover Industry Highlights 
category 2: Events & Webinar 
category 3: Feature 
category 4: Hotel Metasearch Marketing Tips 
category 5: Hotel technology 
category 6: Industry Trends 

Title: trivago Hotel Manager makes Scotland debut at ScotHot 2017 
PubDate: Mar 03, 2017 07:03 AM 
link: http://hotelmanager-blog.trivago.com/trivago-hotel-manager-scotland-debut-scothot-2017/ 
image: 
categories: 4 
category 1: Discover Industry Highlights 
category 2: Direct Bookings 
category 3: Events & Webinar 
category 4: Hotel technology 

Title: Let’s Meet at the World’s Leading Travel Tradeshow – ITB Berlin 
PubDate: Mar 02, 2017 10:03 AM 
link: http://hotelmanager-blog.trivago.com/lets-meet-worlds-leading-travel-tradeshow-itb-berlin/ 
image: 
categories: 2 
category 1: Videos 
category 2: Events & Webinar 
3
  • Hi Adam! Thanks for this. We tried it in our email and got the output as you displayed, but we still arent able to view the images. When I put the %%=v(@image)=%% in the src tag, the image is not displayed, nor is it displayed in your output. Any suggestions?
    – A.Malone
    Commented Mar 21, 2017 at 9:58
  • In addition - I think it also doesn't help that this is our first time doing this and so we are still learning :). The code you provided is much more complex than the initial one we started so we are still trying to learn what each string means. Thanks again for your help!
    – A.Malone
    Commented Mar 21, 2017 at 10:00
  • As I mentioned in my answer, your images don't have separate XML nodes, so you'll need to retrieve the <content> value and parse out the image URL. I'd suggest using a regular expression -- something like this: ((https?:)?//?[^\'"<>]+?\.(jpg|jpeg|gif|png)) Commented Mar 21, 2017 at 11:28

You must log in to answer this question.

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