Hi all, I have an XML file, which can be viewed here, of data concerning a series of music albums, which I would like to load into javascript into an array called "mymusic" in this form:
mymusic = [
{
title:,
artist:,
artwork:,
tracks: [
{
tracktitle:,
trackmp3:
},
{
tracktitle:,
trackmp3:
}
]
}
];
etc.; so basically an array of albums, where each album is represented by a record, the fields of which are the album title, album artist, album artwork, and an array of the album's tracks (where each track/index of the array is represented by a record with fields tracktitle and trackmp3.
In order to achieve this I have the following javascript:
function getxml(){
xmldoc=XML.load('music.xml');
var xmlalbums=xmldoc.getElementsByTagName('album');
mymusic=[];
for(i=0;i<xmlalbums.length;i++){
xmlalbum=xmlalbums[i];
mymusic[i]={};
mymusic[i].title=dataFromTag(xmlalbum,'title');
mymusic[i].artist=dataFromTag(xmlalbum,'artist');
mymusic[i].artwork=dataFromTag(xmlalbum, 'artwork');
tracks=[];
var xmltracks=xmlalbums[i].getElementsByTagName('track');
for(var a=0;a<xmltracks.length;a++){
xmltrack=xmltracks[i];
tracks[i]={};
tracks[i].tracktitle=dataFromTag(xmltrack, 'title');
tracks[i].trackmp3=dataFromTag(xmltrack, 'mp3');
mymusic[i].tracks=tracks;
}
}
}
however, this doesn't load the contents of music.xml in the way I'd like, but I can't see why this is. Any suggestions or help would be appreciated.
Thanks