0

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

7
  • info is an array and you're pushing 7 objects into it for each 'item'. Commented Jun 6, 2013 at 10:48
  • 1
    I suspect you meant to do something like this: info.push({'stage': stage,'title': title,'description': desc,'location': location,'billtype': billtype,'linkurl': linkurl,'thedate':thedate}); Commented Jun 6, 2013 at 10:50
  • you have to define "info" as array and then use the below code to push the items in rows. info[i].push(...) Commented Jun 6, 2013 at 10:52
  • @MasNotsram, yes you have to make the info as multi-dim array Commented Jun 6, 2013 at 10:54
  • So really I over did the curly brackets. Thank you Commented Jun 6, 2013 at 11:41

2 Answers 2

1

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
})
Sign up to request clarification or add additional context in comments.

Comments

1

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
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.