开发者

Parse XML Tag Element in Javascript

开发者 https://www.devze.com 2023-01-19 05:58 出处:网络
I have an xml feed, which i\'m attempting to extract two values from.I\'ll paste the basic xml feed below.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消