2

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">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 Answer 1

2

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 . :)

Sign up to request clarification or add additional context in comments.

2 Comments

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 "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.gif Any ideas on how to combine this with the above?
you could try $weatherinfo.find('current-condition').attr('icon').split('deskwx.weatherbug.com/')[1]; to get "images/Forecast/icons/cond034.gif".

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.