Time for action – parsing and displaying the RSS
To parse and display the RSS perform the following steps:
The RSS fetched in the previous example now needs to be parsed. A new function called
parseRSS
inrssReader.js
will be created. It will be passed the XML fetched from the Web and the code to be called when it is completed. Here is the function in full. We will go through what is going on later.parseRSS = function(_args) { var items = _args.data.documentElement.getElementsByTagName("item"); var data = []; for (var i = 0; i<items.length; i++) { var item = items.item(i); var image; try { var image = item.getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'thumbnail').item(0).getAttribute('url'); } catch (e) { image = ''; } data.push({ title: item.getElementsByTagName('title').item(0).text, link: item.getElementsByTagName('link').item(0).text, description: item.getElementsByTagName('description').item(0).text...