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));
$('.load开发者_运维知识库ingPic').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?
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 . :)
精彩评论