Over a million developers have joined DZone.

Parsing Xml With Actionscript

DZone's Guide to

Parsing Xml With Actionscript

Free Resource
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 
    node had node text
    Album Content


Pick it up piping hot at http://rubyurl.com/q05.

#include "xml_deserializer.as"

/* Sample XML file



// 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(album.song);
    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);

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}