jQuery XML解析如何获取元素属性

sha*_*han 5 xml jquery

XML:

<item>
     <title>Some title</title>

     <description>
     <![CDATA[
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
      Some description text Some description text Some description text Some description text Some description text Some description text 
     ]]>
     </description>

     <media:content isDefault="true" medium="image" url="http://sampledomain.com/image.jpg">
      <media:title>Image title</media:title>
      <media:description>Image description</media:description>
      <media:thumbnail url="http://sampledomain.com/image.jpg" width="160" height="120" />
     </media:content>

     <wfw:commentRss>http://sampledomain.com/comment/feed/</wfw:commentRss>
     <slash:comments>0</slash:comments>
    </item>
Run Code Online (Sandbox Code Playgroud)

我从ajax和onsuccess函数中获取css,我的代码如下:

$(xml).find('item').each(function() {
 var title = $(this).find('title').eq(0).text();
 var url   = $(this).find('content').attr('url');

 // Printing url as undefined
 alert(url);
 console.log($(this).find('content');

});
Run Code Online (Sandbox Code Playgroud)

我想得到什么内容url属性我得到项目的孩子(标题,描述,内容,commentRss和评论),但当我试图得到$(this).find('内容')它不是给我什么任何人都可以它出了我做错了什么?谢谢

jmo*_*253 4

您的 XML 使用命名空间。

请参阅有关命名空间的类似 Stack Overflow 问题。你必须逃避冒号:

jQuery XML 命名空间解析