在 Javascript 中解析 XML 标签元素
我有一个 xml feed,我试图从中提取两个值。我将在下面粘贴基本的 xml feed。
<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 时遇到了麻烦 - 该 url 位于标签本身内 (http://deskwx.weatherbug.com/images/Forecast/icons/cond034.gif)
任何人都可以帮助在上面的js中添加一条语句来读取并显示该值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该会为您提供提要的图标属性。
查看此网站,http://www.switchonthecode.com/tutorials/xml-解析-with-jquery 。 :)
This should get you the icon attribute of the feed.
Check out this site, http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery . :)