Better XML Parsing


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. playlist_arr = new Array();
  2.  
  3. playlist_xml = new XML();
  4. playlist_xml.ignoreWhite = true;
  5. playlist_xml.onLoad = function(success) {
  6. if (success) {
  7. var startTime = getTimer();
  8.  
  9. var track_xml = playlist_xml.firstChild.firstChild;
  10. while (track_xml != null) {
  11. // add the track data to our playlist!
  12. playlist_arr.push(getTrackData(track_xml));
  13. track_xml = track_xml.nextSibling;
  14. }
  15.  
  16. trace("Total parse time: " + (getTimer()-startTime));
  17.  
  18. } else {
  19. trace("Error loading playlist.");
  20. }
  21.  
  22. delete playlist_xml;
  23. }
  24.  
  25. function getTrackData(track_xml) {
  26. var trackData = new Object();
  27.  
  28. var data_xml = new XML();
  29.  
  30. data_xml = track_xml.firstChild;
  31. while (data_xml != null) {
  32. trackData[data_xml.nodeName] = data_xml.firstChild.nodeValue;
  33. data_xml = data_xml.nextSibling;
  34. }
  35.  
  36. return trackData;
  37. }
  38.  
  39. playlist_xml.load("playlist.xml");

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.