Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pushing xml into an array object

    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:

    Code:
    <Players>
      <player>
        <id>1</id>
        <pos>RB</pos>
        <fname>Adrian</fname>
        <lname>Peterson</lname>
        <team>MIN</team>
        <bigname>AdrianPetersonMIN</bigname>
        <adp>2</adp>
        <stddev>1</stddev>
        <ryards>1690</ryards>
        <rtds>13</rtds>
        <rec>25</rec>
        <recyards>185</recyards>
        <rectds>2</rectds>
        <pyards>0</pyards>
        <ptds>0</ptds>
        <intercep>0</intercep>
        <dpts>0</dpts>
        <kpts>0</kpts>
      </player>
    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:

    Code:
    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 
    		alert("help");
    		//testShowPlayers(MyPlayer); 
    		}
    	} 
    
    }
    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:

    Code:
    //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!

  • #2
    pcg
    pcg is offline
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to do the same thing

    Did you ever figure this out? I'm trying to do the exact same thing?

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •