Reputation: 492
I have the following code that collects all information from a RSS feed, and takes out the information I need:
$(xml).find('item').each(function() {
var stage = $(this).attr('p4:stage');
var title = $(this).find('title').text();
var desc = $(this).find('description').text();
var location = $(this).find('category').eq[0];
var billtype = $(this).find('category').eq[1];
var linkurl = $(this).find('link').text();
var thedate = $(this).find('a10\\:updated,updated').text();
thedate = thedate.substring(0,10);
info.push({'stage': stage},{'title': title},{'description': desc},{'location': location},{'billtype': billtype},{'linkurl': linkurl},{'thedate':thedate});
});
console.log(info);
But when I look at what is being sent, its not 1 object with 5 children, each child representing a <item>....contents.....</item>
, but one object with over 200 children, each one containing one part of the <item></item>
, such as:
[0 … 99]
0: Object
stage: "Committee stage"
__proto__: Object
1: Object
title: "Mesothelioma"
__proto__: Object
2: Object
description: "A Bill to establish a diffuse mesothelioma payments scheme and make related provision, and to make provision about the resolution of certain insurance disputes."
__proto__: Object
Could someone help with the code, so I can get whatever number of rss feed items and it's contents to be a child ?
Thanks in advance
Upvotes: 0
Views: 678
Reputation: 296
To place them in one object with 5 properties replace push function with:
info.push({ 'stage': stage, 'title': title, 'description': desc, 'location': location, 'billtype': billtype, 'linkurl': linkurl, 'thedate':thedate })
Upvotes: 1
Reputation: 388316
I think what you need is, one object to be added to info
array for each item
element in the xml with the properties stage, title, description, location, billtype, linkurl
and thedate
info.push({
'stage' : stage,
'title' : title,
'description' : desc,
'location' : location,
'billtype' : billtype,
'linkurl' : linkurl,
'thedate' : thedate
});
Upvotes: 1