Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从XML解析YouTube视频信息_Javascript - Fatal编程技术网

Javascript 从XML解析YouTube视频信息

Javascript 从XML解析YouTube视频信息,javascript,Javascript,给定以下XML输出:,如何遍历所有入口节点以获得yt:videoId值。。。例如: <entry> <id>yt:video:Xyt9rmsxwDU</id> <yt:videoId>Xyt9rmsxwDU</yt:videoId> <yt:channelId>UCBJycsmduvYEL83R_U4JriQ</yt:channelId> <title>I've Mad

给定以下XML输出:,如何遍历所有入口节点以获得
yt:videoId
值。。。例如:

<entry>
    <id>yt:video:Xyt9rmsxwDU</id>
    <yt:videoId>Xyt9rmsxwDU</yt:videoId>
    <yt:channelId>UCBJycsmduvYEL83R_U4JriQ</yt:channelId>
    <title>I've Made 1000 Videos?! Ask MKBHD V26!</title>
    <link rel="alternate" href="https://www.youtube.com/watch?v=Xyt9rmsxwDU"/>
    <author>
        <name>Marques Brownlee</name>
        <uri>https://www.youtube.com/channel/UCBJycsmduvYEL83R_U4JriQ</uri>
    </author>
    <published>2018-03-29T21:11:23+00:00</published>
    <updated>2018-04-02T14:24:16+00:00</updated>
    <media:group>
        <media:title>I've Made 1000 Videos?! Ask MKBHD V26!</media:title>
        <media:content url="https://www.youtube.com/v/Xyt9rmsxwDU?version=3" type="application/x-shockwave-flash" width="640" height="390"/>
        <media:thumbnail url="https://i1.ytimg.com/vi/Xyt9rmsxwDU/hqdefault.jpg" width="480" height="360"/>
        <media:description>
        1K in 4K. JK not all 4K. Still cool tho. The subreddit: http://reddit.com/r/MKBHD The iPhone X Unboxing: https://youtu.be/l0DoQYGZt8M GoPro dog video: https://youtu.be/YyrUBJQmUGs MKBHD Merch: http://shop.MKBHD.com Video Gear I use: http://kit.com/MKBHD/video-gear#recommendation17959 Tech I'm using right now: https://www.amazon.com/shop/influencer-0bfe542e ~ http://twitter.com/MKBHD http://snapchat.com/add/MKBHD http://google.com/+MarquesBrownlee http://instagram.com/MKBHD http://facebook.com/MKBHD
        </media:description>
        <media:community>
            <media:starRating count="43962" average="4.96" min="1" max="5"/>
            <media:statistics views="717951"/>
        </media:community>
    </media:group>
</entry>
使用类似

var nodes = doc.getElementsByTagName("yt:videoId");
var videoIds = [];
for(var i=0;i<nodes.length;i++){
  videoIds.push(nodes.item(i).innerHTML);
}
var nodes = doc.getElementsByTagName("yt:videoId");
var videoIds = [];
for(var i=0;i<nodes.length;i++){
  videoIds.push(nodes.item(i).innerHTML);
}
var nodes = doc.getElementsByTagName("entry").item(0).children
for(...){
  ...
}