如何单独使用jQuery解析xml属性?

我已经成功解析了xml,但我仍然坚持获得孩子们的属性。

XML示例:

     

Javascript / jQuery:

 $.get('data.xml', function(d){ $(d).find('entry').each(function(){ var $entry = $(this); var pic = $entry.find('media:thumbnail').attr('url'); }) }); 

那个javascript对我来说不起作用。 有什么问题?

Aah,命名空间是一种不同的动物,它不在你的原始post中。 你必须在你的选择器中转义:

 var pic = $entry.find('media\\:thumbnail').attr('url'); 

http://jsfiddle.net/JSrJe/1/

另请参阅使用命名空间的jQuery XML解析

试试这个

 $.ajax({ type: "GET", url: 'data.xml, dataType: "xml", success: function(xml) { $(xml).find('entry').each(function(){ var $entry = $(this); var pic = $entry.find('picture').attr('url'); alert(pic); }) }, error: function(xhr, status, error) { if (xhr.status != 404) {alert(error);} else {alert("404 xml not found");} } }) 
  $.get('data.xml', function(d) { $(d).find('entry').each(function() { var $entry = $(this); var pic = $e`enter code here`ntry.find('media\\:thumbnail, thumbnail').attr('url'); }) });