Garry
Garry

Reputation: 33

Javascript to read remote XML file into array

I want to create a multi dimensional array containing artist and track name for 20 songs, based on this file.

http://ws.audioscrobbler.com/2.0/user/bbc6music/weeklytrackchart.xml

So I can create a Spotify app that generates a playlist of the top 20 songs on this list.

Fairly straight forward it seems, but I can't get moving with it.

I would appreciate any help, cheers.

Upvotes: 1

Views: 3109

Answers (1)

user2033671
user2033671

Reputation:

You can use jQuery to fetch the data and parse trough it

$.get("http://ws.audioscrobbler.com/2.0/user/bbc6music/weeklytrackchart.xml",
function(xmlData){
     var $page = $(xmlData);
     //you can now use all the jQuery to conquer the world
     $page.find("track:lt(20)").each(function(){
           var $data = $(this);
           var artistName = $data.find("artist").text();
           //mischief goes here
      });
      //tap the map and say "mischief managed"
 }
);

http://jquery.com/

Upvotes: 3

Related Questions