Return to Snippet

Revision: 3673
at August 30, 2007 08:02 by Bonky


Updated Code
playlist_arr = new Array();

playlist_xml = new XML();
playlist_xml.ignoreWhite = true;
playlist_xml.onLoad = function(success) {
 	if (success) {
  		var startTime = getTimer();
  		
  		var track_xml = playlist_xml.firstChild.firstChild;
  		while (track_xml != null) {
   			// add the track data to our playlist!
   			playlist_arr.push(getTrackData(track_xml));
   			track_xml = track_xml.nextSibling;
   		}
  		
  		trace("Total parse time: " + (getTimer()-startTime));
  		
  	} else {
  		trace("Error loading playlist.");	
  	}
 	
 	delete playlist_xml;
}

function getTrackData(track_xml) {
 	var trackData = new Object();
 	
 	var data_xml = new XML();
 	
 	data_xml = track_xml.firstChild;
 	while (data_xml != null) {
  		trackData[data_xml.nodeName] = data_xml.firstChild.nodeValue;
  		data_xml = data_xml.nextSibling;
  	}
 	
 	return trackData;
}

playlist_xml.load("playlist.xml");

Revision: 3672
at August 30, 2007 08:01 by Bonky


Initial Code
playlist_arr = new Array(); playlist_xml = new XML(); playlist_xml.ignoreWhite = true; playlist_xml.onLoad = function(success) { if (success) { var startTime = getTimer(); var track_xml = playlist_xml.firstChild.firstChild; while (track_xml != null) { // add the track data to our playlist! playlist_arr.push(getTrackData(track_xml)); track_xml = track_xml.nextSibling; } trace("Total parse time: " + (getTimer()-startTime)); } else { trace("Error loading playlist."); } delete playlist_xml; } function getTrackData(track_xml) { var trackData = new Object(); var data_xml = new XML(); data_xml = track_xml.firstChild; while (data_xml != null) { trackData[data_xml.nodeName] = data_xml.firstChild.nodeValue; data_xml = data_xml.nextSibling; } return trackData; } playlist_xml.load("playlist.xml");

Initial URL
http://www.darronschall.com/weblog/archives/000065.cfm

Initial Description

                                

Initial Title
Better XML Parsing

Initial Tags
flash, xml

Initial Language
ActionScript