1

私は何時間も解決策を探し続けてきましたが、私の特定の問題を対象とするものは見つかりませんでした。

私はこのコードを試してきました:

$.ajax({
    url: 'https://gdata.youtube.com/feeds/api/users/profinsights/uploads',
    dataType: "xml",
    success: parseXml    
});

function parseXml(xml) {
    var entrynode = xml.getElementsByTagName("entry");
    $(entrynode).each(function() {
        //console.log($(this));
        console.log($('id',this)); //matches <id successfully
        console.log($('media:group',this)); // no match
    });
}

XMLフラグメント:

...

<entry>
  <id>​http://gdata.youtube.com/feeds/api/videos/870MupRJhmU​&lt;/id>​
  <title type=​"text">​PIMS Humble Beginnings​&lt;/title>​
  <author>​…​&lt;/author>​
  <gd:comments>​…​&lt;/gd:comments>​
  <media:group>​
    <media:category label=​"Education" scheme=​"http:​/​/​gdata.youtube.com/​schemas/​2007/​categories.cat">​Education​&lt;/media:category>​
    <media:content url=​"https:​/​/​www.youtube.com/​v/​870MupRJhmU?version=3&f=user_uploads&app=youtube_gdata" type=​"application/​x-shockwave-flash" medium=​"video" isDefault=​"true" expression=​"full" duration=​"561" yt:format=​"5">​&lt;/media:content>​
    <media:content url=​"rtsp:​/​/​v3.cache3.c.youtube.com/​CigLENy73wIaHwllhkmUugy98xMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/​0/​0/​0/​video.3gp" type=​"video/​3gpp" medium=​"video" expression=​"full" duration=​"561" yt:format=​"1">​&lt;/media:content>​
    <media:content url=​"rtsp:​/​/​v1.cache7.c.youtube.com/​CigLENy73wIaHwllhkmUugy98xMYESARFEgGUgx1c2VyX3VwbG9hZHMM/​0/​0/​0/​video.3gp" type=​"video/​3gpp" medium=​"video" expression=​"full" duration=​"561" yt:format=​"6">​&lt;/media:content>​
    <media:description type=​"plain">​…​&lt;/media:description>​
    <media:keywords>​…​&lt;/media:keywords>​
    <media:player url=​"https:​/​/​www.youtube.com/​watch?v=870MupRJhmU&feature=youtube_gdata_player">​&lt;/media:player>​
    <media:thumbnail url=​"http:​/​/​i.ytimg.com/​vi/​870MupRJhmU/​0.jpg" height=​"360" width=​"480" time=​"00:​04:​40.500">​&lt;/media:thumbnail>​
    <media:thumbnail url=​"http:​/​/​i.ytimg.com/​vi/​870MupRJhmU/​1.jpg" height=​"90" width=​"120" time=​"00:​02:​20.250">​&lt;/media:thumbnail>​
    <media:thumbnail url=​"http:​/​/​i.ytimg.com/​vi/​870MupRJhmU/​2.jpg" height=​"90" width=​"120" time=​"00:​04:​40.500">​&lt;/media:thumbnail>​
    <media:thumbnail url=​"http:​/​/​i.ytimg.com/​vi/​870MupRJhmU/​3.jpg" height=​"90" width=​"120" time=​"00:​07:​00.750">​&lt;/media:thumbnail>​
    <media:title type=​"plain">​PIMS Humble Beginnings​&lt;/media:title>​
    <yt:duration seconds=​"561">​&lt;/yt:duration>​
  </media:group>
​&lt;/entry>

...
  • 私の目標は、次のような名前の各ノードからテキストノードと属性を取得することです。<media:foo>
  • ノードmedia:groupを照合するためのセレクター が間違っていることはわかっています。できれば、xmlセレクターの専門家がこれを処理する方法についてアドバイスをくれることを願っています。

前もって感謝します。

編集:ところで、上記のコードのフィドルは次のとおりです:http: //jsfiddle.net/vYJwm/

更新

問題は解決しました。みんなありがとう。

4

1 に答える 1

0

これを試して:

http://jsfiddle.net/gRoberts/vYJwm/3/

jQuery はそれらを asmedia:fooではなく moreとして解析していますfoo

それが役立つことを願っていますか?

于 2012-07-19T13:03:13.160 に答える