gpt4 book ai didi

javascript - 在 Javascript 中解析 XML 标记元素

转载 作者:行者123 更新时间:2023-11-29 22:38:55 25 4
gpt4 key购买 nike

我有一个 xml 提要,我正试图从中提取两个值。我将在下面粘贴基本的 xml 提要。

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

为了解析这个提要,我在 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);
});
});
});

这对于获取“MoSTLy Cloudy”文本效果很好。但现在我无法形成一个声明来显示图标 url - 它位于标签本身 (http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif)

谁能帮忙附加一条语句来在上面的 js 中读取和显示这个值?

最佳答案

这应该让您获得提要的图标属性。

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

查看此站点,http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery . :)

关于javascript - 在 Javascript 中解析 XML 标记元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3903324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com