-
Problem traversing XML object
Hi
I am experiencing problems when trying to traverse XMl returned from the youtube data api
I can trace the XML but cannot access any of the nodes, not sure where I'm going wrong, I have tried various methods including parsing JSON format from youtube but to no avail.
I thought it maybe the namespaces so I replaced these using a script to replace them as attributes. A snippet of returned XML is below:
<feed xmlns_app="http://purl.org/atom/app#" xmlns_media="http://search.yahoo.com/mrss/" xmlns_openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns_gd="http://schemas.google.com/g/2005" xmlns_yt="http://gdata.youtube.com/schemas/2007" xmlns="http://www.w3.org/2005/Atom">
<id>http://gdata.youtube.com/feeds/api/videos</id>
<updated>2011-09-18T11_17_03.084Z</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_ Afrojack</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=Afrojack+&start-index=1&max-results=25"/>
<link rel="next" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos?q=Afrojack+&start-index=26&max-results=25"/>
<author>
<name>YouTube</name>
<uri>http://www.youtube.com/</uri>
</author>
<generator version="2.1" uri="http://gdata.youtube.com">YouTube data API</generator>
<openSearch_totalResults>8777</openSearch_totalResults>
<openSearch_startIndex>1</openSearch_startIndex>
<openSearch_itemsPerPage>25</openSearch_itemsPerPage>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/TUoOcDGMgT4</id>
<published>2010-10-20T14_04_06.000Z</published>
<updated>2011-09-18T06_19_21.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="Music" label="Music"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Afrojack"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Eva"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Simons"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Take"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Over"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="Control"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="ministry"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="of"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="sound"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="dance"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="music video"/>
<category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="high quality"/>
<title type="text">Afrojack feat Eva Simons - Take Over Control (OUT NOW!)</title>
<content type="text">Buy now from iTunes_ bit.ly The brand new video from Ministry of Sound, this is Afrojack feat Eva Simons - Take Over Control, and it's out now! Follow Ministry of Sound on Twitter www.twitter.com and Facebook www.facebook.com</content>
<link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=TUoOcDGMgT4&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/TUoOcDGMgT4/responses"/>
<link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/TUoOcDGMgT4/related"/>
<link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=TUoOcDGMgT4"/>
<link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/TUoOcDGMgT4"/>
<author>
<name>datarecordsuk</name>
<uri>http://gdata.youtube.com/feeds/api/users/datarecordsuk</uri>
</author>
<gd_comments>
<gd_feedLink href="http://gdata.youtube.com/feeds/api/videos/TUoOcDGMgT4/comments" countHint="8555"/>
</gd_comments>
<media_group>
<media_category label="Music" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Music</media_category>
<media_content url="http://www.youtube.com/v/TUoOcDGMgT4?f=videos&app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="185" yt_format="5"/>
<media_content url="rtsp://v8.cache8.c.youtube.com/CiILENy73wIaGQk-gYwxcA5KTRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="185" yt_format="1"/>
<media_content url="rtsp://v5.cache4.c.youtube.com/CiILENy73wIaGQk-gYwxcA5KTRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="185" yt_format="6"/>
<media_description type="plain">Buy now from iTunes_ bit.ly The brand new video from Ministry of Sound, this is Afrojack feat Eva Simons - Take Over Control, and it's out now! Follow Ministry of Sound on Twitter www.twitter.com and Facebook www.facebook.com</media_description>
<media_keywords>Afrojack, Eva, Simons, Take, Over, Control, ministry, of, sound, dance, music video, high quality</media_keywords>
<media_player url="http://www.youtube.com/watch?v=TUoOcDGMgT4&feature=youtube_gdata_play er"/>
<media_thumbnail url="http://i.ytimg.com/vi/TUoOcDGMgT4/0.jpg" height="360" width="480" time="00_01_32.500"/>
<media_thumbnail url="http://i.ytimg.com/vi/TUoOcDGMgT4/1.jpg" height="90" width="120" time="00_00_46.250"/>
<media_thumbnail url="http://i.ytimg.com/vi/TUoOcDGMgT4/2.jpg" height="90" width="120" time="00_01_32.500"/>
<media_thumbnail url="http://i.ytimg.com/vi/TUoOcDGMgT4/3.jpg" height="90" width="120" time="00_02_18.750"/>
<media_title type="plain">Afrojack feat Eva Simons - Take Over Control (OUT NOW!)</media_title>
<yt_duration seconds="185"/>
</media_group>
<gd_rating average="4.8642874" max="5" min="1" numRaters="38191" rel="http://schemas.google.com/g/2005#overall"/>
<yt_statistics favoriteCount="72670" viewCount="17624746"/>
</entry>
</feed>
CODE:
XML.ignoreWhitespace = true;
var xmlString:XML = new XML(event.target.data);
var modified:String = xmlString.replace("xmlns=", "xmlns:default=");
var pattern:RegExp = new RegExp("?!/)", "gi");
var transmuted:String = modified.replace(pattern, "_");
var ab:String = transmuted.toString();
var zones:XML;
zones=new XML(ab);
trace(zones); //traces XML document
//trace(zones[0].entry[0].id) // produces a term has no properties
//trace(zones[0].feed[0].entry[0].id) //produces undefined
Any help with this is greatly appreciated
Thanks
-
You code looks AS2 and yes it is. So use this code in a fla timeline and save the fla and the feed.xml file in same directory. And test it.
Actionscript Code:
var xml:XML = new XML(); xml.ignoreWhite = true; xml.onLoad = function(success) { var node = xml.firstChild; trace(node.attributes.xmlns_app); trace(node.attributes.xmlns_media); trace(node.childNodes[0].firstChild); }; xml.load("feed.xml");
FFA
-
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|