DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Parsing Xml With Actionscript

  • submit to reddit
        The Xml Deserializer functions parse an XML file and give you a basic object of the nodes and attributes.  Using the discography xml fragment below as an example, you can do:


// this is if the <album> node had node text
// <album title="blah">Album Content</album>

Pick it up piping hot at

#include ""

/* Sample XML file
  <album title="Late For The Sky" year="1974">
    <song title="Late For The Sky" href="late_for_the_sky.mp3"/>
    <song title="Fountain Of Sorrow" href="fountain_of_sorrow.mp3"/>

// xml callback function
function parseDiscography(success) {
  if(!success) return;
  XmlDeserializer.parse_nodes(myData, XmlDeserializer.xml_object.childNodes[0]);

  var albums = XmlDeserializer.get_items(myData.album);
  for(var a=0; a < albums.length; a++) {
    var album = albums[a];
    var songs = XmlDeserializer.get_items(;
    for(var s=0; s < songs.length; s++) {
      var song = songs[s];
      if(song._href != undefined) {
        var song_obj = { 
          title: album._title + ' :: ' + song._title,
          href: myDiscoPath + song._href

        // global array used by flash

// object used by XmlDeserializer class
var myData = {};
// strip off disco.xml
var myDiscoPath = myDisco.substr(0, myDisco.length-9); 
//XmlDeserializer.debug = true;

// myDisco is url to discography xml file
XmlDeserializer.parse_xml(myDisco, parseDiscography);