// Assuming there are somewhere that you can get Google RSS
var xmlData = document.getElementById('xmldata').innerHTML;
// [1] Parse the xml feed into an array of JS objects
function parseData(data) {
parser = new DOMParser();
var xmlDoc = parser.parseFromString(data, "text/xml");
// Convert collection to array
// getElementsByTagName returns a collection/NodeList instead of an array.
// It will be more convenient if we could use it like an array.
var items = Array.from(xmlDoc.getElementsByTagName('item'));
var feeds = [];
items.forEach(function(item) {
feeds.push({
title: getNode(item, 'title'),
link: getNode(item, 'link'),
pubDate: getNode(item, 'pubDate'),
description: getNode(item, 'description'),
});
});
return feeds;
}
var googleFeeds = parseData(xmlData);
// [2] Using the feeds array
// This code shows how the data can be accessed
var target = document.getElementById('target');
googleFeeds.forEach(function(item) {
var itemList = document.createElement('li');
var itemAnchor = document.createElement('a');
var itemParagraph = document.createElement('p');
itemAnchor.setAttribute('target', '_blank');
itemAnchor.setAttribute('href', item.link); // obtaining the link
itemAnchor.innerText = item.title; // obtaining the title
itemParagraph.innerHTML = item.description; // obtaining the title
itemList.appendChild(itemAnchor);
itemList.appendChild(itemParagraph);
target.appendChild(itemList);
});
// Retrieve the data of a specific tag
function getNode(node, tagToRetrieve) {
var htmlData = node.getElementsByTagName(tagToRetrieve)[0].innerHTML;
return _.unescape(htmlData); // decode HTML entities, see lodash/underscore
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.