Extract XML element value from a RSS feed



I have a RSS feed and I need to extract the latest pubDate element from it for my test. What is the best way to do the same ?


RSS Feed link: http://ift.tt/1vwvBLu


Sample XML:



<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:atom="http://ift.tt/r5ut6F">
<channel>
<atom:link href="http://ift.tt/1vwvBLu" rel="self" type="application/rss+xml" />
<link>http://ift.tt/1ujT3VN;
<title>Hyper-Reach Automated Test Account alerts feed "Automated RSS Test"</title>
<description>Constant feed of alerts from Automated Test Account via hyper-reach.com</description>
<lastBuildDate>Fri, 21 Nov 2014 00:56:15 -0500</lastBuildDate>
<language>null</language>
<ttl>5</ttl>
<item>
<title>Alert (2014-11-21)</title>
<pubDate>Fri, 21 Nov 2014 00:56:15 -0500</pubDate>
<description>This is a test message.</description>
<link>http://ift.tt/1vwweom;
<guid isPermaLink="false">http://ift.tt/1ujT2Bi;
</item>
<item>...</item>
<item>...</item>
</channel>
</rss>


What I am doing:



checkRSSFeed = function() {
//first I navigate to a certain page in my website
var href = '';

casper.then(function() {
this.test.assertExists(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'the element exists');
href = casper.getElementAttribute(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'href');
}).then(function() {
this.open(href);
}).then(function() {
this.echo(this.getCurrentUrl());

var pubDate = '';
this.getPageContent();
pubDate = this._utils_.getElementByXPath('.//pubDate');
});
};


The error I am getting is



uncaughtError: TypeError: 'undefined' is not an object (evaluating 'this._utils_.getElementByXPath')



No comments:

Post a Comment