parsing xml with actionscript
1 2 myData.album._title 3 myData.album.song[0]._href; 4 5 // this is if the <album> node had node text 6 // <album title="blah">Album Content</album> 7 myData.album.__content__
Pick it up piping hot at http://rubyurl.com/q05.
1 2 #include "xml_deserializer.as" 3 4 /* Sample XML file 5 <discography> 6 <album title="Late For The Sky" year="1974"> 7 <song title="Late For The Sky" href="late_for_the_sky.mp3"/> 8 <song title="Fountain Of Sorrow" href="fountain_of_sorrow.mp3"/> 9 </album> 10 </discography> 11 */ 12 13 // xml callback function 14 function parseDiscography(success) { 15 if(!success) return; 16 17 XmlDeserializer.parse_nodes(myData, XmlDeserializer.xml_object.childNodes[0]); 18 19 play(); 20 21 var albums = XmlDeserializer.get_items(myData.album); 22 for(var a=0; a < albums.length; a++) { 23 var album = albums[a]; 24 var songs = XmlDeserializer.get_items(album.song); 25 for(var s=0; s < songs.length; s++) { 26 var song = songs[s]; 27 if(song._href != undefined) { 28 var song_obj = { 29 title: album._title + ' :: ' + song._title, 30 href: myDiscoPath + song._href 31 }; 32 33 // global array used by flash 34 mySongs.push(song_obj); 35 } 36 } 37 } 38 } 39 40 // object used by XmlDeserializer class 41 var myData = {}; 42 // strip off disco.xml 43 var myDiscoPath = myDisco.substr(0, myDisco.length-9); 44 //XmlDeserializer.debug = true; 45 46 // myDisco is url to discography xml file 47 XmlDeserializer.parse_xml(myDisco, parseDiscography);