views:

48

answers:

1

Hi there, I have an xml feed, which i'm attempting to extract two values from. I'll paste the basic xml feed below.

<aws:weather>
     <aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif"&gt;Mostly Cloudy</aws:current-condition>
</aws:weather>

To parse this feed, I have the following in Javascript:

$(document).ready(function(){
    $.get('http://xmlfeed-with-private-api-access.xml', function(d){

    $(d).find('weather').each(function(){

    var $weatherinfo = $(this); 
    var winfo = $weatherinfo.find('current-condition').text();

    var winformation = winformation += '<span>' + winfo + '</span>' ;
    $('#sydinfo').append($(winformation));

    $('.loadingPic').fadeOut(1400);
    });
    });
});

Which works just fine to get the "Mostly Cloudy" text. But now I'm having trouble forming a statement to display the icon url - which is housed within the tag itself (http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif)

Would anyone please be able to help append a statement to read and display this value within the above js?

+1  A: 

This should get you the icon attribute of the feed.

$weatherinfo.find('current-condition').attr('icon');

Check out this site, http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery . :)

Karthick
Thanks a million, that worked a treat.
Nelga
Could i please ask a quick followup... The script above works great, but i would also like to change the output slightly. Say, the output is "http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif"I would then like to alter this address to point at a local image: themes/app/images/Forecast/icons/cond034.gifAny ideas on how to combine this with the above?
Nelga
you could try $weatherinfo.find('current-condition').attr('icon').split('http://deskwx.weatherbug.com/')[1]; to get "images/Forecast/icons/cond034.gif".
Karthick
Thanks!! You're a legend
Nelga