Solved

capturing some xml but not all

Posted on 2013-11-13
3
254 Views
Last Modified: 2013-11-13
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
0
Comment
Question by:powerztom
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 300 total points
ID: 39645067
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
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 200 total points
ID: 39645071
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
 

Author Closing Comment

by:powerztom
ID: 39646186
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now