开发者

Parsing using mrss

开发者 https://www.devze.com 2023-01-07 07:44 出处:网络
I\'m trying to parse an mrss feed using jquery but am having some difficulty targeti开发者_如何转开发ng thechild element.

I'm trying to parse an mrss feed using jquery but am having some difficulty targeti开发者_如何转开发ng the child element.

Code:

$(xml).find("item").each(function(){
   var $item = $(this);
   alert($item.find("media\\:thumbnail").text();
});

MRSS Structure:

<media:thumbnail url="http://somewebsite.com/someimage.jpg" />

UPDATE The solution $item.find("media\:thumbnail").attr("url") works very well in Firefox but running the code in Chrome reveals an undefined value. Can someone suggest a workaround.

Thanks


You're trying to display the text() of your found nodes. The example node you include has no text at all. You want the value of the url attribute:

$(xml).find("item").each(function(){
    var $item = $(this);
    alert($item.find("media\\:thumbnail").attr("url"));
});

If your media:thumbnail element had something between opening and closing tags you could use text() (and you still wouldn't be getting the url value):

<media:thumbnail url="http://somesite.com/simeimage.jpg">Some text string</media:thumbnail>
0

精彩评论

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