我正在研究一个使用codeigniter和youtube api的项目,我请求一个视频,我得到了一些XML,我的问题是我不知道该怎么处理所说的XML,或者更重要的是如何解析它,这样我就可以得到我想要的值,我得到它的XML,
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005'
xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc</id>
<published>2010-11-29T21:28:22.000Z</published>
<updated>2011-03-14T12:01:51.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='Travel' label='Travel & Events'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Barney'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Harwood'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Interview'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='children's'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bafta'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='awards'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='2010'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='red'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='carpet'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='host'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='tv'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='television'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='show'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='presenter'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='prank'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='patrol'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='the'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='sorcerer's'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='apprentice'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bbc'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='cbbc'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bear'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='behaving'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='badly'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='nev'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='smile'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='totally'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='doctor'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='who'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='basil's'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='swap'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='shop'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='basil'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='brush'/>
<title type='text'>Barney Harwood Interview</title>
<content type='text'>Barney Harwood Interview - We talk to children's TV presenter Barney Harwood on the red carept, ahead of his duties as host for the Children's BAFTA Awards 2010 in London. Presented by Michael Kurn Camera and Post by Russell Nelson</content>
<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=x33JD3-hXHc&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/x33JD3-hXHc/responses'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.ratings' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/ratings'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.complaints' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/complaints'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/related'/>
<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=x33JD3-hXHc'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc'/>
<author>
<name>LeicesterSquareTV</name>
<uri>http://gdata.youtube.com/feeds/api/users/leicestersquaretv</uri>
</author>
<gd:comments>
<gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/x33JD3-hXHc/comments' countHint='5'/>
</gd:comments>
<yt:hd/>
<media:group>
<media:category label='Travel & Events' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Travel</media:category>
<media:content url='http://www.youtube.com/v/x33JD3-hXHc?version=3&f=videos&d=Ac2cvuTKQbM_TEZ_NAvfWNEO88HsQjpE1a8d1GxQnGDm&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='150' yt:format='5'/>
<media:content url='rtsp://v4.cache7.c.youtube.com/CkULENy73wIaPAl3XKF_D8l9xxMYDSANFEgGUgZ2aWRlb3NyIQHNnL7kykGzP0xGfzQL31jRDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='150' yt:format='1'/>
<media:content url='rtsp://v2.cache5.c.youtube.com/CkULENy73wIaPAl3XKF_D8l9xxMYESARFEgGUgZ2aWRlb3NyIQHNnL7kykGzP0xGfzQL31jRDvPB7EI6RNWvHdRsUJxg5gw=/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='150' yt:format='6'/>
<media:description type='plain'>Barney Harwood Interview -We talk to children's TV presenter Barney Harwood on the red carept, ahead of his duties as host for the Children's BAFTA Awards 2010 in London. Presented by Michael Kurn
Camera and Post by Russell Nelson
</media:description>
<media:keywords>Barney, Harwood, Interview, children's, bafta, awards, 2010, red, carpet, host, tv, television, show, presenter, prank, patrol, the, sorcerer's, apprentice, bbc, cbbc, bear, behaving, badly, nev, smile, totally, doctor, who, basil's, swap, shop, basil, brush
</media:keywords>
<media:player url='http://www.youtube.com/watch?v=x33JD3-hXHc&feature=youtube_gdata_player'/>
<media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/0.jpg' height='360' width='480' time='00:01:15'/>
<media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/1.jpg' height='90' width='120' time='00:00:37.500'/>
<media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/2.jpg' height='90' width='120' time='00:01:15'/>
<media:thumbnail url='http://i.ytimg.com/vi/x33JD3-hXHc/3.jpg' height='90' width='120' time='00:01:52.500'/>
<media:title type='plain'>Barney Harwood Interview</media:title><yt:duration seconds='150'/>
</media:group>
<gd:rating average='5.0' max='5' min='1' numRaters='1' rel='http://schemas.google.com/g/2005#overall'/>
<yt:statistics favoriteCount='0' viewCount='1141'/>
</entry>
具体来说,我如何获得缩略图?
我建议你开始阅读simpleXML
如果你还不明白,你可以在这里找到一个更容易理解,但更简单的教程
我不确定您是否正在使用我开发的库。这是链接。如果你是,那么有一个'alt'参数,你可以传递到你的库调用,这将让你指定你想要的数据返回方式。如果你将其设置为JSON,那么你可以使用PHP内置的json_decode函数。
即使你不使用我的库,你仍然可以使用alt参数,只要在你的GET uri上指定它。