Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

pulling xml data from two different sections for one player

I just discovered a flaw in the code I'm using and that code grabs infomation for the current play in a basketball xml game cast. This code will go and pull everything right except the Points and Assists.  In this example the xml file attached after Linescore attib values there is a players node outside the team players And this Players node That has current player play description and Points and Assists well Points and Assists are for that play and not the points and assists scored the game. And that is what I need is the points and assists for the entire game. So I'm not sure how to but match the player's team Id with Team id for entire team lineup then match the player's player Id with Player ID for entire team lineup. then grab POINTS AND ASSISTS In this attached xml file for Players node the player is Michael Carter-Williams has Players Points and Assists are both 0. But his Points and Assists under team lineup is Points = 4 and Assists = 3 that is what I need to display everything else display is perfect except Points and Assists. So Please help. Any questions just ask. Thanks EE

HERE IS SOURCE CODE
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
body {
	background-color: #000;
}
#apDiv1 {
	position: absolute;
	width: 619px;
	height: 376px;
	z-index: 10;
	left: 75px;
	top: 12px;
}
.apdivtbheader {
	color: #FFF;
}
.centermid {
	font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
	font-size: 16px;
	font-weight: bold;
	color: #000;
	text-align: center;
	vertical-align: middle;
}
.headertop {
	color: #000080;
}
</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 = '18749'; 
		$(document).ready(function(){
			$.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameID + ".xml",
                    dataType: "xml",
                    success: function (data) {
                        var d = $(data);
						 d.find('Team').each(function(i,Team){
          var team = $(Team);
          var vh = team.attr('vh'); // A or H...
          var sHomeOrAway = vh == 'H' ? 'home' : 'away';
          $('#txt' + sHomeOrAway).html(team.attr('name'));
		  if ($(Team).attr('vh') == "H") {
                        //convert the XML into a jQuery object
 $('#imgcourt').attr('src', 'http://dev.sportsnetwork.com/aspdata/nhl2/NBA/Images/Courts/' + team.attr('ID')  + '.png');
           // getStats(player,txt,img,li);
           
							 }
        });
					
                   
                    }
                });	
	 });	
	
		//}

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');
                            $('#txtgameplay').html(msg);   
							$('#txttimeleft').html(inn);
                             $('#txtplaytype').html(playtype1);  
                        
                        //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
	
               // if (player.size() > 0) {
                                
                             //$.each(players,function(i,player) {
          player=$(player);
        var tid = player.attr('TeamID');
         var pid =  player.attr('ID');  
		 var pts =  player.attr('Points')
		 var assists = player.attr('Assists')
		  $('#txtpoints').html(pts);
          //  $("#players").append(li);
			$('txtassists').html(assists);
             $('#imgcenter').attr('src', 'http://dev.sportsnetwork.com/aspdata/nhl2/NBA/Images/NBAlOGOSZ/'+ tid +".png");
           
			
			$('#imgplayer').attr("src","http://images.sportsnetwork.com/bask/nba/atthecourt/players/" + pid + ".jpg");
           var txt = player.attr("Firstname") + " " +
                player.attr("Lastname") + ", " +
                player.attr("Position");
           // getStats(player,txt,img,li);
           $('#txt1').html(txt);
							// }
     //   });

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

<body>
<table width="750" border="0">
  <tr>
    <td><div align="center">
      <div id="apDiv1">
        <table width="650" border="0">
          <tr class="headertop">
            <td width="121" bgcolor="#FFFFFF"><div align="center" id="txt1"></div></td>
            <td width="114" bgcolor="#FFFFFF"><div align="center"><strong>TimeLeft</strong></div></td>
            <td width="122" bgcolor="#FFFFFF"><div align="center"><strong>PlayType</strong></div></td>
            <td width="120" bgcolor="#FFFFFF"><div align="center"><strong>Points</strong></div></td>
            <td width="120" bgcolor="#FFFFFF"><div align="center"><strong>Assits</strong></div></td>
          </tr>
          <tr class="apdivtbheader">
            <td height="52" class="centermid"><p><img src="Images/misc/invisibleplayer.png" name="imgplayer" width="50" height="50" id="imgplayer"></p></td>
            <td class="centermid" id="txttimeleft"></td>
            <td class="centermid" id="txtplaytype"></td>
            <td class="centermid" id="txtpoints"></td>
            <td class="centermid" id="txtassists"></td>
          </tr>
        </table>
        <table width="120" border="0">
          <tr>
            <td><p class="centermid"><img src="Images/misc/invisibleteamlogo.png" name="imgcenter" width="133" height="117" id="imgcenter"></p></td>
          </tr>
</table>
        <table width="263" border="0">
          <tr>
            <td height="18" id="txtgameplay"><p class="centermid" id="txtgameplay">&nbsp;</p>
              <p class="centermid">&nbsp;</p></td>
          </tr>
    </table>
        
      </div>
    <img src="Images/Courts/096.png" width="625" height="375" id = "imgcourt"></div></td>
  </tr>
</table>
<script>
var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{

loadData();

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

Open in new window

Court3.html
18672.XML
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Not entirely sure what you mean, as you're XML structure seems a little odd. Your code doesn't really make a whole lot of sense either. What happened to the code I'd helped you with previously - you seem to have reverted back to your own, which makes 2 separate calls for the XML data, and on the second call assigns the resulting data to 2 different variables:

d = $(data);
gameData = $(data);

Can't really see why you're doing this.

Does the Players node only ever have 1 player in it. Do you want to get this player, and then grab his details from the Individual Stats node and use them?

Need a bit of a clearer explanation of what you want
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Powers
Tom Powers

ASKER

Perfect Chris exactly they way I need it. You are a EE Top Gun!
Chris,

Need to hijack your brain for a few minutes. Automatic Horizontal scrolling scoreboard tables for NHL Daily Games.

https://www.experts-exchange.com/questions/28301645/Scoreboard-doesn't-display-xml-data.html