capturing some xml but not all

I have a xml file in which general data is defined at the top under play attribute, then there is   a node that most of the time appears called PLAYERS that is the node I am having problems grabbing data from. Here is the code


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>The Court</title>
<style type="text/css">
body {
	background-color: #000;
}
#apDiv1 {
	position: absolute;
	width: 554px;
	height: 374px;
	z-index: 10;
	left: 106px;
	top: 33px;
}
.centermid {
	text-align: center;
	vertical-align: text-mid;
}
.centermid2 {
	text-align: center;
	vertical-align: middle;
}
.centermid3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 20px;
	font-weight: bold;
	text-align: center;
	vertical-align: middle;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var xmlPath = '.' //'/xml/nba/scores/real';
        var xmlGameID = '18672'; 
		
function loadData() {
 $.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameID + ".xml",
                    dataType: "xml",
                    success: function (data) {
                        var d = $(data);
						 var Play = d.find('Play');
						  var msg;
						  var inn = Play.attr('TimeLeft');
						 var playtype1 = Play.attr('PlayType');
      msg = Play.find('narrative').attr('text');
                            $('#txtGametext').html(msg);   
							$('#time').html(inn);
                             $('#playtype').html(playtype1);  
                        
                         var Players = $(d.find('Players'));
                if (Players.size() > 0) {
                                
                             //$.each(players,function(i,player) {
          ///  player=$(player);
        var tid = Players.attr('TeamID');
         var pid =  Players.attr('ID');   
             $('#imgcenter').attr('src', 'http://dev.sportsnetwork.com/aspdata/nhl2/NBA/Images/NBAlOGOSZ/'+ tid +".png");
           var txt;
			
			$('#imgplayer').attr("src","http://images.sportsnetwork.com/bask/nba/atthecourt/players/" + pid + ".jpg");
            txt = " " +
                Players.attr("FirstName") + " " +
                Players.attr("Lastname") + ", " +
                Players.attr("Pos");
           // getStats(player,txt,img,li);
            $('#txtpts').html(Players.attr("Points"));
          //  $("#players").append(li);
			$('txtassists').html(Players.attr("Assists"));
							 }
     //   });

                    //    });
                    }
                });	
}
</script>
</head>

<body>
<table width="750" border="0">
  <tr>
    <td><div align="center">
      <div id="apDiv1">
        <table width="100%" border="0">
          <tr>
            <td width="18%" height="97" rowspan="2"><div align="center"><img src="Images/misc/player.jpg" name="imgplayer" width="60" height="80" id="imgplayer"></div></td>
            <td width="20%" rowspan="2" class="centermid" id="time">&nbsp;</td>
            <td width="22%" rowspan="2"><p class="centermid2" id="playtype">&nbsp;</p>
              <p class="centermid2" id="playtype">&nbsp;</p>
              <p id="playtype">&nbsp;</p></td>
            <td width="19%" class="centermid2" id="lblpoints">Points</td>
            <td width="21%" class="centermid2" id="lblassists">Assists</td>
          </tr>
          <tr>
            <td height="54" class="centermid3" id="txtpts">&nbsp;</td>
            <td width="21%" class="centermid3" id="txtassists">&nbsp;</td>
          </tr>
        </table>
        <table width="103" height="91" border="0">
          <tr>
            <td width="97" height="87"><img src="http://dev.sportsnetwork.com/aspdata/nhl2/NBA/Images/NBAlOGOSZ/101.png" name="imgcenter" width="100" height="96" id="imgcenter"></td>
          </tr>
</table>
        <table width="300" border="0">
          <tr>
            <td height="97"><p align="center" id="txtGametext">&nbsp;</p></td>
          </tr>
      </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      </div>
    <img src="http://dev.sportsnetwork.com/aspdata/nhl2/NBA/Images/Courts/099.png" width="625" height="375"></div></td>
  </tr>
</table>
<script>
var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{

loadData();

}
</script>
</body>
</html>

Open in new window

I need playerid for headshot teamid for team logo and the players current points and assists. Please Assist Help EE
Court.html
18672.XML
powerztomAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
leakim971Connect With a Mentor PluritechnicianCommented:
This node :
<Players>
<Player ID="2411" TeamID="106" Firstname="Michael" Lastname="Carter-Williams" Number="1" Position="G" FGAtt="0" FGMade="0" TresMade="0" TresAtt="0" FTMade="0" FTAtt="0" ORebounds="0" DRebounds="0" Assists="1" PerFouls="0" Steals="0" Turnovers="0" BlockedShots="0" Points="0" TechnicalFouls="0"/>
</Players>

Open in new window


Inside you've ONE Player
Look like you try to get attr of this ONE Player but your current code try to get the attr of the Players

replace :
var Players = $(d.find('Players'));
by :
var Players = $('Players Player', d)

or to get the first if there's more than one Player inside Players :
var Players = $('Players Player:first', d);
or the last one:
var Players = $('Players Player:last', d);
0
 
Chris StanyonConnect With a Mentor Commented:
You access the info like this:

//convert the XML into a jQuery object
gameData = $(data);

//Get the Players node
players = gameData.find('Players');

//Now loop through each Player in the Players node
$('Player', players).each(function(i, player) {
	//Output some of the attributes for this player
	console.log($(player).attr("ID"));
	console.log($(player).attr("TeamID"));
});

Open in new window

0
 
powerztomAuthor Commented:
Both EE Guys provided examples that both worked for me and both were a little different so I got to learn a extra little bit. Nice work guys
0
All Courses

From novice to tech pro — start learning today.