Solved

capturing some xml but not all

Posted on 2013-11-13
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 43

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

751 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