Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> parsowanie simpleXML, parsowanie simpleXML
lucas666
post 17.08.2011, 22:57:59
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 12.07.2010

Ostrzeżenie: (0%)
-----


Witam. Mam problem, poniewaz nie wiem, jak dobrac sie do opisu (media:description).

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/"DU8BQn0ycSp7ImA9WhdQFkw."'>
  3. <id>tag:youtube.com,2008:user:datarecordsuk:uploads</id>
  4. <updated>2011-08-17T21:50:53.399Z</updated>
  5. <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
  6. <title>Uploads by datarecordsuk</title>
  7. <logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
  8. <link rel='related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk'/>
  9. <link rel='alternate' type='text/html' href='http://www.youtube.com/profile_videos?user=datarecordsuk'/>
  10. <link rel='hub' href='http://pubsubhubbub.appspot.com'/>
  11. <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads'/>
  12. <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads/batch'/>
  13. <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads?start-index=1&max-results=25'/>
  14. <link rel='service' type='application/atomsvc+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads?alt=atom-service'/>
  15. <link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads?start-index=26&max-results=25'/>
  16. <author>
  17. <name>datarecordsuk</name>
  18. <uri>http://gdata.youtube.com/feeds/api/users/datarecordsuk</uri>
  19. </author>
  20. <generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator>
  21. <openSearch:totalResults>240</openSearch:totalResults>
  22. <openSearch:startIndex>1</openSearch:startIndex>
  23. <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
  24. <entry gd:etag='W/"C0cCQX47eCp7ImA9WhdQFkw."'>
  25. <id>tag:youtube.com,2008:video:Ul-ASO5CO4g</id>
  26. <published>2011-08-09T15:32:35.000Z</published>
  27. <updated>2011-08-17T19:57:40.000Z</updated>
  28. <app:control>
  29. <yt:state name='restricted' reasonCode='limitedSyndication'>Syndication of this video was restricted by its owner.</yt:state>
  30. </app:control>
  31. <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
  32. <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/>
  33. <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Wolfgang Gartner'/>
  34. <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Will.I.Am'/>
  35. <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Black Eyed Peas'/>
  36. <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Forever'/>
  37. <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Ministry of Sound'/>
  38. <title>Wolfgang Gartner ft. Will.I.Am - 'Forever' (Out 09.10.11)</title>
  39. <content type='application/x-shockwave-flash' src='http://www.youtube.com/v/Ul-ASO5CO4g?f=user_uploads&app=youtube_gdata'/>
  40. <link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=Ul-ASO5CO4g&feature=youtube_gdata'/>
  41. <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/Ul-ASO5CO4g/responses'/>
  42. <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/Ul-ASO5CO4g/related'/>
  43. <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads/Ul-ASO5CO4g'/>
  44. <author>
  45. <name>datarecordsuk</name>
  46. <uri>http://gdata.youtube.com/feeds/api/users/datarecordsuk</uri>
  47. </author>
  48. <yt:accessControl action='comment' permission='allowed'/>
  49. <yt:accessControl action='commentVote' permission='allowed'/>
  50. <yt:accessControl action='videoRespond' permission='moderated'/>
  51. <yt:accessControl action='rate' permission='allowed'/>
  52. <yt:accessControl action='embed' permission='allowed'/>
  53. <yt:accessControl action='list' permission='allowed'/>
  54. <yt:accessControl action='autoPlay' permission='moderated'/>
  55. <yt:accessControl action='syndicate' permission='denied'/>
  56. <gd:comments>
  57. <gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/Ul-ASO5CO4g/comments' countHint='85'/>
  58. </gd:comments>
  59. <media:group>
  60. <media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category>
  61. <media:content url='http://www.youtube.com/v/Ul-ASO5CO4g?f=user_uploads&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='174' yt:format='5'/>
  62. <media:credit role='uploader' scheme='urn:youtube'>datarecordsuk</media:credit>
  63. <media:description type='plain'>Ministry of Sound is pleased to announce the addition of Wolfgang Gartner to one of the hottest labels in the world. Gartner's new single, 'Forever', a collaboration with Will.I.Am, is already receiving heavy plays from Radio 1, Capital, Kiss and beyond.
  64.  
  65. Gartner is the Grammy-nominated US star championed by everyone from Zane Lowe to Pete Tong and Annie Mac to Nick Grimshaw. And that's just some of the UK radio DJs. Throw in the likes of Deadmau5, Tiesto, and David Guetta, and you have a figure that's being tipped for global domination by dance music's biggest figures.
  66.  
  67. As the front man for one of the most successful acts of this century with the Black Eyed Peas, Will.I.Am needs little introduction. This collaboration with Gartner cements his domination of the world of dance music. Expect nothing less than a huge video featuring Will as he's never been seen before...
  68.  
  69. 'Forever' is released on 9th October 2011 on Ministry of Sound Recordings.
  70.  
  71. <a href="http://www.ministryofsound.com" target="_blank">http://www.ministryofsound.com</a></media:description>
  72. <media:keywords>Wolfgang Gartner, Will.I.Am, Black Eyed Peas, Forever, Ministry of Sound</media:keywords>
  73. <media:player url='http://www.youtube.com/watch?v=Ul-ASO5CO4g&feature=youtube_gdata_player'/>
  74. <media:restriction type='country' relationship='deny'>DE</media:restriction>
  75.  


  1. $url="http://gdata.youtube.com/feeds/api/users/datarecordsuk/uploads";
  2. $data=simplexml_load_file($url);
  3.  
  4.  
  5. $tytul = $data->entry->title;
  6. $data = $data->entry->updated;
  7. [u][b]$opis = $data->entry->media->media:description;[/b][/u]




Z gory dzieki za pomoc;)
Go to the top of the page
+Quote Post
Noidea
post 18.08.2011, 06:45:33
Post #2





Grupa: Zarejestrowani
Postów: 226
Pomógł: 61
Dołączył: 20.08.2010

Ostrzeżenie: (0%)
-----


http://www.php.net/manual/en/simplexmlelement.children.php

drugi przykład


--------------------
Go to the top of the page
+Quote Post
lucas666
post 18.08.2011, 08:55:40
Post #3





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 12.07.2010

Ostrzeżenie: (0%)
-----


ok;) poradzilem sobie, tylko nie wiem jak zrobic, aby wyciagnac tylko jeden opis...

  1. foreach ($sxml->entry as $entry) {
  2. // get nodes in media: namespace for media information
  3. $media = $entry->children('http://search.yahoo.com/mrss/');
  4.  
  5. // get video player URL
  6. $attrs = $media->group->player->attributes();
  7. $watch = $attrs['url'];
  8.  
  9. // get video thumbnail
  10. $attrs = $media->group->thumbnail[0]->attributes();
  11. $thumbnail = $attrs['url'];
  12.  
  13. // get <yt:duration> node for video length
  14. $yt = $media->children('http://gdata.youtube.com/schemas/2007');
  15. $attrs = $yt->duration->attributes();
  16. $length = $attrs['seconds'];
  17.  
  18. // get <yt:stats> node for viewer statistics
  19. $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
  20. $attrs = $yt->statistics->attributes();
  21. $viewCount = $attrs['viewCount'];
  22.  
  23. // get <gd:rating> node for video ratings
  24. $gd = $entry->children('http://schemas.google.com/g/2005');
  25. if ($gd->rating) {
  26. $attrs = $gd->rating->attributes();
  27. $rating = $attrs['average'];
  28. } else {
  29. $rating = 0;
  30. }
  31.  
  32. $opis = $media->group->description[0];
  33. echo $opis;
  34. echo $watch;
  35. }


w ten sposob wyciaga opisy do wszystkich filmikowm jakie tam sa, a mi zalezy tylko na jednym, np. pierwszym;)

Ten post edytował lucas666 18.08.2011, 08:59:44
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 22.06.2025 - 19:24