View Full Version : pushing xml into an array object

09-01-2009, 04:18 PM
I use personal projects to teach myself code and this is one of those.... I'm trying to import an xml document into a JS array. Basically, I want an array of football players with statistics regarding their fantasy football draft positions, std. deviations, etc. so I can maximize my team in my upcoming fantasy draft lol. Important stuff here, I tell ya... but its a good way to learn JS.

I'm pretty sure, by the alerts and messages I send myself in the code to test various points, that I have a successful httpRequest with appropriate status responses. The problem comes down to when I try to push the xml data into the array object.

I don't want to post my whole script, but I'm not positive where exactly the problem is.... so I'll post code in order of most to least important:

First, here's a snippet from the xml file:


Pretty simple.... a bunch of "Players" broken down into "player" with data on each player.

Here's the code where I'm trying to import the data into an object array:

function runDraft() {

//testing how far I got
document.getElementById("playtest").innerHTML = "i really really Hate stuff";

if (xhr.readyState == 4) {
if (xhr.status == 200) {
document.getElementById("anotherone").innerHTML = "what the hell";

var xmlData = xhr.responseXML.getElementsByTagName("Players")[0];

// Add value to the player array
var ply = xmlData.getElementsByTagName("player");
for (var i=0; i<ply.length; i++) {
document.getElementById("anotherone").innerHTML = "what the hell2";
//Create the player objects

player.push(new myPlayer(getText(ply[i].getElementsByTagName("id")[0]), getText(ply[i].getElementsByTagName("pos")[0]), getText(ply[i].getElementsByTagName("fname")[0]), getText(ply[i].getElementsByTagName("lname")[0]), getText(ply[i].getElementsByTagName("team")[0]), getText(ply[i].getElementsByTagName("adp")[0]), getText(ply[i].getElementsByTagName("stddev")[0]), getText(ply[i].getElementsByTagName("ryards")[0]), getText(ply[i].getElementsByTagName("rtds")[0]), getText(ply[i].getElementsByTagName("rec")[0]), getText(ply[i].getElementsByTagName("recyards")[0]), getText(ply[i].getElementsByTagName("rectds")[0]), getText(ply[i].getElementsByTagName("pyards")[0]), getText(ply[i].getElementsByTagName("ptds")[0]), getText(ply[i].getElementsByTagName("intercep")[0]), getText(ply[i].getElementsByTagName("dpts")[0]), getText(ply[i].getElementsByTagName("kpts")[0])));
//test by showing the entire player list


on the web page, the "what the hell2" is coming through, but the alert("help") never happens.

Also of importance may be the myPlayer object:

//create the player object
function myPlayer(id, pos, fname, lname, team, adp, stddev, ryds, rtds, rec, recyds, rectds, pyds, ptds, intercept, dpts, kpts) {
this.id = id;
this.pos = pos;
this.fname = fname;
this.lname = lname;
this.team = team;
this.adp = adp;
this.stddev = stddev;
this.ryds = ryds;
this.rtds = rtds;
this.rec = rec;
this.recyds = recyds;
this.rectds = rectds;
this.pyds = pyds;
this.ptds = ptds;
this.intercept = intercept;
this.dpts = dpts;
this.kpts = kpts;

Any help is very much appreciated and will be rewarded with animal sacrifices and burnt offerings in your honor forever ensuring that you get a pretend-special place in heaven.

And if I win my league, you'll get .000000009% of the proceeds!

11-23-2009, 08:15 PM
Did you ever figure this out? I'm trying to do the exact same thing?