I would suggest this:
var reminders = [];
$('reminder',xml).each(function(i) { // apply this function to each reminder (index as parameter)
var $this=$(this); // each applies the function so that 'this' is the relevant element
reminders[i] = {
id:$this.find("id").text(),
date:$this.end().find("date").text(), // end() because the previous find("id") is persistent
event:$this.end().find("event").text(),
start:$this.end().find("start").text(),
end:$this.end().find("end").text(),
};
});

Blair

On 11/2/06, Richard Clare <[EMAIL PROTECTED]> wrote:

Hey jqueriers

 

I have a php script that returns a list of event reminders as an xml document. I need to parse this with jquery and build a multi dimensional array of the reminders contained therein.

 

I've got as far as this with jquery (and that took me long enough!):

 

$.post("reminders.php",{},function(xml){

  var text = $('event', xml).text();

  alert(text);

});

 

The xml looks like this:

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<reminders>

  <reminder>

    <id>1</id>

    <event>Richards Birthday</event>

    <date>2006-09-03</date>

    <start>9:30</start>

    <end>13:30</end>

  </reminder>

  <reminder>

    <id>2</id>

    <eventid>7</eventid>

    <event>Pay Day</event>

    <date>2006-09-03</date>

    <start>9:30</start>

    <end>13:30</end>

  </reminder>

</reminders>

 

At the moment jquery is getting every 'event' node so the _javascript_ variable text = 'Richards BirthdayPay Day' – I would like to split this and put the stuff into an array. How do I do this?

 

Hope this is clear.

 

Thanks

 

Richard


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.23/513 - Release Date: 02/11/2006


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to