Parse RSS in ExactTarget

I was recently tasked with migrating a few themes from Mailchimp to Exact Target. While the overall experience I had working with ExactTarget was much less than stellar, I most disliked working with RSS feeds. The whole process of parsing an RSS feed seemed awkward.

So, in an effort to help others, and because I never want to figure out how to parse RSS for Exact Target again, here is how you can use RSS feeds within your Exact Target templates.

Create a Content Area

The method described to me by Exact Target’s support requires that the RSS be stored in a content area within the Exact Target interface. To do this, you will need to create an HTML content area and place the following within it:

[code]%%before;httpget;1"http://domain.com/rss"%%%5B/code%5D

This piece of code will fetch the contents of the RSS feed each time the content area is called.

For example, when we use ContentAreaByName("My Contentsrss_featured"), the RSS is being fetched and stored at that time.

Parse the RSS Contents

Actually parsing the RSS feed and getting the desired output was a bit more difficult since Exact Target uses what I believe is a proprietary language named AMPscript.

Thankfully, the Exact Target support came through with a snippet of code that gave me a good head start. I took that snippet and built the following.

[code]
%%[
Var @xml, @titles, @title, @descs, @desc, @links, @link, @cnt, @dates, @date
Set @xml = ContentAreaByName("My Contentsrss_featured") /* This line specifies the content area from which the RSS content will be pulled for the email message. */
Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
Set @dates = BuildRowsetFromXML(@xml, "//item/pubDate", 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 @desc = Field(Row(@descs,@cnt), "Value")
Set @link = Field(Row(@links,@cnt), "Value")
Set @date = Format(DateParse(Field(Row(@dates,@cnt), "Value")),"MMM d, yyyy h:mm tt")
]%%

<div class="feed-item" style="background:#444;padding:10px 10px 0;margin-bottom:20px;border-left:4px solid #222;"><span style="color:#ffffff;font-size:16px;line-height:20px;margin-bottom:12px;">%%=v(@title)=%%</span>
<span style="color:#cccccc;font-size:12px;line-height:20px;margin-bottom:12px;">%%=v(@date)=%%</span>
<a style="text-decoration:underline;font-weight:normal;color:#336699 !important;" href="%%=RedirectTo(@link)=%%">More info…</a>
</div>

%%[
NEXT @cnt
ENDIF
]%%
[/code]

This snippet pulls out the Title, Description, Link, and Publication Date for each item in an RSS feed and puts it into what I consider to be an array.

The next is to then loop through these items, up to 5 rows worth, and get each value. Once we have these values stored in variables we can then place them in templates using the following syntax: %%=v(@varName)=%%.

The biggest caveat in displaying the information was with inserting a link into the template. Notice that in the above example, %%=RedirectTo(@link)=%%, there is an extra call to RedirectTo. This has to do with the tracking system that Exact Target uses.

Questions?

This short article is meant as an introduction into how to parse RSS with Exact Target. I hope that this answers any questions you may have, but if you’d like more information, please leave a comment below and I’ll be sure to help you out.

4 responses to “Parse RSS in ExactTarget”

  1. In email if i clicked on View as web page and refreshed it and new feed is loaded will the link to that feed works?

    1. Hello there! Thanks for leaving a comment.

      It’s been quite a while since I’ve used ExactTarget, and I only used it for a specific client. So, I’m afraid I’m not too familiar with how to answer your question. :/

  2. Hi! Speaking of never wanting to do something again, I never want to try to google my way through trying to figure out how to add images to my ExactTarget RSS feed again, and yet I still need to because we haven’t figured it out yet 🙁 Have you had any luck in this department?

    1. Hi Ashley,

      It’s been about 3 years since I’ve worked with ExactTarget, and even then, it was only for one client. So, I don’t think I’ll be any help. Sorry :/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.