JavaScript和XML:获取具有命名空间的节点的节点值。

时间:2017-01-30 17:01:31

标签: javascript xml

我需要从media:thumbnail节点获取值,但是我似乎无法访问它。

XML

<entry>
  <id>yt:video:9fvH8E_EsOc</id>
  <yt:videoId>9fvH8E_EsOc</yt:videoId>
  <yt:channelId>UCeNOYP-TQK-3P3JZerCjheQ</yt:channelId>
  <title>BMW 530d M Sport Touring in 60 seconds!</title>
  <link rel="alternate" href="http://www.youtube.com/watch?v=9fvH8E_EsOc" />
  <author>
    <published>2017-01-30T14:18:55+00:00</published>
    <updated>2017-01-30T16:12:44+00:00</updated>
    <media:group>
    <media:title>BMW 530d M Sport Touring in 60 seconds!</media:title>
    <media:content url="https://www.youtube.com/v/9fvH8E_EsOc?version=3" type="application/x-shockwave-flash" width="640" height="390" />
    <media:thumbnail url="https://i2.ytimg.com/vi/9fvH8E_EsOc/hqdefault.jpg" width="480" height="360" />
    <media:description>This spec to death 5 Series is jam packed with goodies, what does Jake make of it!?</media:description>
    <media:community>
  </media:community>
</media:group>

JavaScript的:

var id = (result[x].id).split(':')[2],
                    cont = $('<div>', {'class' : 'flexible-frame'}),
                    frame = $('<iframe>', {
                      src: 'http://www.youtube.com/embed/' + id + '?contols=' + settings.controls +
                            '&rel=' + settings.rel +
                            '&showinfo=' + settings.showinfo +
                            '&cc_load_policy=' + settings.cc_load_policy +
                            '&disablekb=' + settings.disablekb +
                            '&fs=' + settings.fs +
                            '&loop=' + settings.loop +
                            '&modestbranding=' + settings.modestbranding,
                      frameborder: settings.frameborder,
                      width: settings.size[0],
                      height: settings.size[1],
                      allowfullscreen: settings.allowfullscreen
                    });
                    // thumb = $('<img>', {
                    //   src: ((result[x]['media:group'])['media:thumbnail']).getAttribute('url')
                    // });
                    console.log(result[x]['media:group']);
                    cont.append(frame);

0 个答案:

没有答案