【问题标题】:unable to query each element from this xml. i have to fetch title, id,无法从此 xml 查询每个元素。我必须获取标题,ID,
【发布时间】:2010-08-25 07:10:02
【问题描述】:
<?xml version='1.0' encoding='UTF-8'?>
<feed >
<id>http://gdata.youtube.com/feeds/api/videos</id>
<updated>2010-08-24T13:18:29.767Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<title type='text'>YouTube Videos matching query: aa</title>
<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='alternate' type='text/html' href='http://www.youtube.com'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos'/>
<link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/batch'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=aa&amp;start-index=1&amp;max-results=25'/>
<link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=aa&amp;start-index=26&amp;max-results=25'/>

<author>
    <name>YouTube</name>
 <uri>http://www.youtube.com/</uri>
</author>


<generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator>


<openSearch:totalResults>484223</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>

<openSearch:itemsPerPage>25</openSearch:itemsPerPage>

<entry>

 <id>http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c</id>

 <published>2007-12-30T23:11:39.000Z</published>

 <updated>2010-08-24T02:30:36.000Z</updated>

 <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Tech' label='Science &amp; Technology'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='AA-12'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='AA'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='12'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='AA12'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='automatic'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='shotgun'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='weapon'/>

 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='weapons'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='military'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='hardware'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='assault'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='blackwater'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='firearms'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='army'/>
 <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='american'/>

 <title type='text'>AA-12. World's deadliest shotgun!</title>


 <content type='text'>weblink: tinyurl.com Blackwater firearms: www.blackwaterusa.com</content>

 <link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=p4ebtj1jR7c&amp;feature=youtube_gdata'/>
 <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c/responses'/>
 <link rel='http://gdata.youtube.com/schemas/2007#video.ratings' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c/ratings'/>
 <link rel='http://gdata.youtube.com/schemas/2007#video.complaints' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c/complaints'/>
 <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c/related'/>
 <link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=p4ebtj1jR7c'/>
 <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c'/>


 <author><name>MFS357</name><uri>http://gdata.youtube.com/feeds/api/users/mfs357</uri></author><gd:comments><gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/p4ebtj1jR7c/comments' countHint='15208'/></gd:comments><media:group><media:category label='Science &amp; Technology' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Tech</media:category><media:content url='http://www.youtube.com/v/p4ebtj1jR7c?f=videos&amp;d=ARZEzGI7ejBt-fukjjc3kIAO88HsQjpE1a8d1GxQnGDm&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='384' yt:format='5'/><media:content url='rtsp://v3.cache3.c.youtube.com/CkULENy73wIaPAm3R2M9tpuHpxMYDSANFEgGUgZ2aWRlb3NyIQEWRMxiO3owbfn7pI43N5CADvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='384' yt:format='1'/><media:content url='rtsp://v4.cache8.c.youtube.com/CkULENy73wIaPAm3R2M9tpuHpxMYESARFEgGUgZ2aWRlb3NyIQEWRMxiO3owbfn7pI43N5CADvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='384' yt:format='6'/><media:description type='plain'>weblink: tinyurl.com Blackwater firearms: www.blackwaterusa.com</media:description><media:keywords>AA-12, AA, 12, AA12, automatic, shotgun, weapon, weapons, military, hardware, assault, blackwater, firearms, army, american</media:keywords><media:player url='http://www.youtube.com/watch?v=p4ebtj1jR7c&amp;feature=youtube_gdata_player'/><media:thumbnail url='http://i.ytimg.com/vi/p4ebtj1jR7c/2.jpg' height='90' width='120' time='00:03:12'/><media:thumbnail url='http://i.ytimg.com/vi/p4ebtj1jR7c/1.jpg' height='90' width='120' time='00:01:36'/><media:thumbnail url='http://i.ytimg.com/vi/p4ebtj1jR7c/3.jpg' height='90' width='120' time='00:04:48'/><media:thumbnail url='http://i.ytimg.com/vi/p4ebtj1jR7c/0.jpg' height='240' width='320' time='00:03:12'/><media:title type='plain'>AA-12. World's deadliest shotgun!</media:title><yt:duration seconds='384'/></media:group><gd:rating average='4.774384' max='5' min='1' numRaters='12180' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='27463' viewCount='7607670'/></entry></feed>

需要从这个xml中获取title、id和其他内部值,尝试作为xml.feed.title和其他选项来...

【问题讨论】:

    标签: xml apache-flex flash actionscript-3


    【解决方案1】:

    xml 变量引用根标签本身。所以你不需要在你的 e4x 中引用feed。

    var feed:XML = new XML(theString);
    trace(feed.entry.title);
    trace(feed.entry.id);
    trace(feed.entry.author.name);
    

    看起来 xml 使用了一些命名空间,如 openSearch、gd 等,但它们的声明不存在。

    【讨论】:

      【解决方案2】:

      对于每个视频条目,您可以这样:

      xml.entry[index] //this will give you the XMLList for 'index' numbered video
      xml.entry[index].title 
      xml.entry[index].id  //these will give you title and id for corresponding videos 

      【讨论】:

        猜你喜欢
        • 2021-02-19
        • 2014-01-05
        • 2019-07-19
        • 2013-07-25
        • 1970-01-01
        • 2015-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多