Tom Powers
asked on
get specific Data from xml field
Ok I have a html page player image and xml file attached. What I need to solve this is to grab from the xml file a node called pitcher it's located in the beginning of the file I need to grab Firstname and Lastname and ID that will be used for a head shot.
<Pitcher ID="1770" TeamID="007" FirstName="Kyle " Lastname="Farnsworth" Inning="6" Outs="1" Throws="R" BBats="S" AB="1" BF="1"/> if you can pull this name and headshot player ID you have succeeded if like the page pulls Zack Wheeler not working right. Because there are 2 Pitcher's list Current pitcher after score then at the end of the xml pitchers a list of games pitchers.
here is the code Thanks EE
This is the 2nd pitchers list not current pitcher this will pull Zack Wheller as pitcher and not current pitcher
<Pitcher ID="1770" TeamID="007" FirstName="Kyle " Lastname="Farnsworth" Inning="6" Outs="1" Throws="R" BBats="S" AB="1" BF="1"/>
fieldplayers.html
040-unif-home.gif
<Pitcher ID="1770" TeamID="007" FirstName="Kyle " Lastname="Farnsworth" Inning="6" Outs="1" Throws="R" BBats="S" AB="1" BF="1"/> if you can pull this name and headshot player ID you have succeeded if like the page pulls Zack Wheeler not working right. Because there are 2 Pitcher's list Current pitcher after score then at the end of the xml pitchers a list of games pitchers.
here is the code Thanks EE
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="css/jquery-ui-1.8.9.customver1.css">
<style type="text/css">
.GCPBP {
color: white;
}
#apDiv1 {
position: absolute;
width: 17px;
height: 28px;
z-index: 10;
left: 218px;
top: 368px;
}
#apDiv2 {
position: absolute;
width: 16px;
height: 34px;
z-index: 20;
left: 197px;
top: 368px;
}
#apDiv3 {
position: absolute;
width: 21px;
height: 30px;
z-index: 25;
left: 197px;
top: 308px;
}
#apDiv4 {
position: absolute;
width: 17px;
height: 33px;
z-index: 30;
left: 289px;
top: 295px;
}
#apDiv5 {
position: absolute;
width: 16px;
height: 33px;
z-index: 35;
left: 320px;
top: 303px;
}
#apDiv6 {
position: absolute;
width: 19px;
height: 32px;
z-index: 40;
left: 225px;
top: 276px;
}
#apDiv7 {
position: absolute;
width: 24px;
height: 38px;
z-index: 45;
left: 173px;
top: 261px;
}
#apDiv8 {
position: absolute;
width: 14px;
height: 37px;
z-index: 46;
left: 136px;
top: 268px;
}
#apDiv9 {
position: absolute;
width: 21px;
height: 32px;
z-index: 50;
left: 99px;
top: 282px;
}
#apDiv10 {
position: absolute;
width: 20px;
height: 38px;
z-index: 55;
left: 67px;
top: 290px;
}
#apDiv11 {
position: absolute;
width: 17px;
height: 37px;
z-index: 60;
left: 321px;
top: 254px;
}
#apDiv12 {
position: absolute;
width: 19px;
height: 35px;
z-index: 65;
left: 205px;
top: 235px;
}
#apDiv13 {
position: absolute;
width: 18px;
height: 37px;
z-index: 70;
left: 69px;
top: 244px;
}
#P,#C,#FB,#SB,#SS,#TB,#LF,#CF,#RF , #HPUmpire,#TBUmpire,#SBUmpire,#FBUmpire {
/*border: 1px solid white;*/
}
</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/mlb/scores/real';
var xmlGameID = '41880';
var srcFieldTeamLogo;
//var playerImage;
var txtpitcher;
//var pitcherid;
var intPosID = {
'P': {
pos: 'Pitcher',
id: 0,
name: 'unknown'
},
'C': {
pos: 'Catcher',
id: 0,
name: 'unknown'
},
'FB': {
pos: 'First Base',
id: 0,
name: 'unknown'
},
'SB': {
pos: 'Second Base',
id: 0,
name: 'unknown'
},
'SS': {
pos: 'ShortStop',
id: 0,
name: 'unknown'
},
'TB': {
pos: 'Third Base',
id: 0,
name: 'unknown'
},
'LF': {
pos: 'Left Field',
id: 0,
name: 'unknown'
},
'CF': {
pos: 'Center Field',
id: 0,
name: 'unknown'
},
'RF': {
pos: 'Right Field',
id: 0,
name: 'unknown'
},
'HPUmpire': {
pos: 'Home Plate Umpire',
id: 0,
name: 'unknown'
},
'TBUmpire': {
pos: 'Third Base Umpire',
id: 0,
name: 'unknown'
},
'SBUmpire': {
pos: 'Second Base Umpire',
id: 0,
name: 'unknown'
},
'FBUmpire': {
pos: 'First Base Umpire',
id: 0,
name: 'unknown'
}
};
stadiums = {
"wrigley field":"wrigley.gif",
"comerica park":"comerica.gif" ,
"yankee stadium":"yankee.jpg" ,
"shea stadium":"shea.jpg" ,
"angel stadium of anaheim":"angel.jpg" ,
"rangers ballpark in arlington":"angel.jpg" ,
"at&t park":"attpark.jpg" ,
"citizens bank park":"citizenballpark.jpg" ,
"coors field":"coors.jpg" ,
"busch stadium":"busch.jpg" ,
"oriole park at camden yards":"camden_baltimore.jpg",
"dodger stadium":"dodgers.jpg" ,
"chase field":"chasefield.jpg" ,
"tropicana field":"tropicana.jpg" ,
"great american ball park":"greatamerican.jpg" ,
"kauffman stadium":"kauffmanstadium.jpg" ,
"mcafee coliseum":"mcafeecoliseum.jpg" ,
"hubert h. humphrey metrodome":"metrodome.jpg" ,
"metrodome":"metrodome.jpg" ,
"miller park":"millerpark.jpg" ,
"minute maid park":"minutemaid.jpg" ,
"nationals park":"nationalspark.jpg" ,
"petco park":"petcopark.jpg" ,
"pnc park":"pncpark.jpg" ,
"progressive field":"progressive.jpg" ,
"rogers centre":"rogerscentre.jpg" ,
"safeco field":"safecofield.jpg" ,
"turner field":"turnerfield.jpg" ,
"dolphin stadium":"dolphinstadium.jpg" ,
"fenway park":"fenwaypark.jpg" ,
"u.s. cellular field":"uscellularfield.jpg" ,
"oakland-alameda county coliseum":"mcafeecoliseum.jpg",
"marlins park":"marlins.jpg",
"citi field":"citifield.jpg",
"target field":"targetfield.jpg"
}; // no comma on the last
var homeTurf = {
"minnesota":"target field",
"philadelphia":"citizens bank park",
"milwaukee":"miller park",
"san francisco":"u.s. cellular field",
"la angels":"angel stadium of anaheim",
"tampa bay":"tropicana field",
"chicago wsox":"u.s. cellular field",
"oakland":"oakland-alameda county coliseum",
"kansas city":"kauffman stadium",
"los angeles":"dodger stadium",
"san diego":"petco park",
"boston":"fenway park",
"seattle":"safeco field",
"detroit":"comerica park",
"atlanta":"turner field",
"baltimore":"oriole park at camden yards",
"miami":"marlins park",
"pittsburgh":"pnc park",
"ny mets":"citi field",
"st. louis":"busch stadium",
"houston":"minute maid park",
"cleveland":"progressive field",
"cincinnati":"great american ball park",
"texas":"rangers ballpark in arlington",
"toronto":"rogers centre",
"chicago cubs":"wrigley field",
"arizona":"chase field",
"colorado":"coors field",
"ny yankees":"yankee stadium",
"washington":"nationals park"
};
$(document).ready(function(){
$.ajax({
type: "GET",
url: xmlPath+"/"+xmlGameID+".xml",
dataType: "xml",
success: function(data){
var d = $(data);
var Play = d.find('Play');
var Teams = $(data).find("Team");
$.each(Teams,function(i,Team) {
team=$(Team);
var id = team.attr("ID").toLowerCase();
var homeOrAway = team.attr("vh");
$(homeOrAway=="H" ? '#imghometeam' : '#imgawayteam').attr('src', 'http://sportsnetwork.com/MLB/MLB/' + id + ".png");
var name = team.attr("name").toLowerCase();
if (homeOrAway=="H") {
var stadium_location = stadiums[homeTurf[name]]; // or have
var url = "http://images.sportsnetwork.com/mlb/attheballpark/stadiums/";
url = (stadium_location) ?url + stadium_location:"default.gif";
$("#imgStad").attr("src",url);
}
var loc = Play.attr('Location') ;
//var locate = "Location" + $('#txtBallparkname').html(loc).toUpperCase;
$('#txtBallparkname').html("Location " + loc.toUpperCase());
});
}
});
$('#P,#C,#FB,#SB,#SS,#TB,#LF,#CF,#RF').hover(function(){
$('#playerImage').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/players/'+intPosID[this.id].id+'.jpg');
$('#PlayerName').html(intPosID[this.id].name);
$('#PositionName').html(intPosID[this.id].pos);
},function() {
$('#playerImage').attr('src', 'http://sportsnetwork.com/gamecast/mlb/Images/blank.png');
$('#PlayerName').html(' ');
$('#PositionName').html(' ');
});
$('#HPUmpire,#TBUmpire,#SBUmpire,#FBUmpire').hover(function(){
$('#playerImage').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/umpires/'+intPosID[this.id].id+'.jpg');
$('#PlayerName').html(intPosID[this.id].name);
$('#PositionName').html(intPosID[this.id].pos);
},function() {
$('#playerImage').attr('src', 'http://sportsnetwork.com/gamecast/mlb/Images/blank.png');
$('#PlayerName').html(' ');
$('#PositionName').html(' ');
});
});
function loadAll() {
$.ajax({
type: "GET",
url: xmlPath+"/"+xmlGameID+".xml",
dataType: "xml",
success: function(data){
var d = $(data);
if (d.find('Play').attr("Status").toUpperCase() === "FINAL") {
clearInterval(myVar);
}
var colNodes = d.find('Play').children();
for (var i=0; i < colNodes.length; i++) {
var objNode = colNodes[i];
//document.getElementById("demo").innerHTML += '/'+objNode.nodeName;
switch(objNode.nodeName) {
case 'Batter':
txtBatter = $(objNode).attr('FirstName') + ' ' + $(objNode).attr('Lastname');
intBatter = $(objNode).attr('ID');
intBatterSave = intBatter;
break;
case 'Pitcher':
txtPitcher = $(objNode).attr('FirstName') + ' ' + $(objNode).attr('Lastname');
intPitcher = $(objNode).attr('ID');
break;
}
}
// if (d.find('Play').attr("NoPlay").toUpperCase() === '1') {
// $('#txtBallparkname').html("Rain Delay");
// clearInterval(myVar);
// }
// if (d.find('Play').attr("NoPlay").toUpperCase() === '0') {
// setInterval(myVar);
// }
for (var posItem in intPosID) {
posItem.updated = false;
}
$(d.find('Pitcher')).each(function(i, nodePlayer){ // always 1!
nodePlayer = $(nodePlayer);
var posItem = intPosID['P'];
if (posItem) { // && !posItem.updated
posItem.id = nodePlayer.attr('ID');
posItem.name = nodePlayer.attr('FirstName') + ' ' + nodePlayer.attr('Lastname');
posItem.updated = true;
//tempCount++;
}
});
$(d.find('Fielders')).find('Player').each(function(indexPlayer, nodePlayer){
nodePlayer = $(nodePlayer);
var posItem = intPosID[nodePlayer.attr('Pos').trim().replace('1B', 'FB').replace('2B', 'SB').replace('3B', 'TB')];
if (posItem) {
posItem.id = nodePlayer.attr('ID');
posItem.name = nodePlayer.attr('FirstName') + ' ' + nodePlayer.attr('Lastname');
posItem.updated = true;
} else {
//console.log('invalid player positem: ' + nodePlayer.attr('Pos'));
}
});
$(d.find('Umpires')).find('*').each(function(indexUmpire, nodeUmpire){
nodeUmpire = $(nodeUmpire);
var posItem = intPosID[nodeUmpire.prop('nodeName')];
if (posItem) {
posItem.id = nodeUmpire.attr('ID');
posItem.name = nodeUmpire.text();
posItem.updated = true;
} else {
//console.log('invalid umpire positem: ' + nodeUmpire.prop('nodeName'));
}
});
/*
var tempCount = 0;
for (var posItem in intPosID) {
if (!posItem.updated) {
tempCount++;
}
}
$('#txtBallparkname').html('temp debug: ' + tempCount + ' items NOT updated');
*/
var tempCount = 0;
var intPitcherTeamID = d.find('Pitcher').attr('TeamID');
var intBatterTeamID = d.find('Batter').attr('TeamID');
$('#imgawayteam').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/MLB/' +intBatterTeamID + ".png");
$('#imghometeam').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/MLB/' + intPitcherTeamID + ".png");
// BattersSameTeamAsPitcher
$(d.find('Batters[TeamID="' + intPitcherTeamID + '"]')).find('Player').each(function(i, nodePlayer){
nodePlayer = $(nodePlayer);
var posPlayer = nodePlayer.attr('Pos').replace('1B', 'FB').replace('2B', 'SB').replace('3B', 'TB');
var posItem = intPosID[posPlayer];
if (posItem) { // && !posItem.updated
posItem.id = nodePlayer.attr('ID');
posItem.name = nodePlayer.attr('FirstName') + ' ' + nodePlayer.attr('Lastname');
posItem.updated = true;
tempCount++;
}
});
//$('#txtBallparkname').html('temp debug: ' + tempCount + ' items extra updated!');
var Fielder = $(d.find('Fielders').find('Player:first'));
var Team = $(d.find("Team[ID='" + Fielder.attr('TeamID') + "']"));
var unfrm = Team.attr('Uniform'); // +'.gif';
$('#P,#C,#FB,#SB,#SS,#TB,#LF,#CF,#RF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+unfrm);
//srcFieldTeamLogo = 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('ID')+'.png';
//var d = $(data);
//var Pitchers = $(d.find('Batters').find('Player:first'));
///var Team = $(d.find("Team[ID='" + Batter.attr('TeamID') + "']"));
//var unfrm = Team.attr('Uniform');
//var bat = Batter.attr("Bats");
//if (srcFieldTeamLogo != "") $('#srcFieldTeamLogo').attr('src', srcFieldTeamLogo);
}
})
}
</script>
</head>
<body bgcolor="#000000" class="GCPBP">
<table width="100%" border="0">
<tr>
<td><strong class="GCPBP" id="txtBallparkname">BallParkname</strong></td>
</tr>
</table>
<table width="400" border="0">
<tr>
<td><table width="400" border="0">
<tr>
<td width="67" rowspan="4"><p><img src="BBLogo.png" alt="" name="imghometeam" width="78" height="76" id="imghometeam"></p></td>
<td width="81" rowspan="4"><img src="Images/Blank.png" alt="" width="73" height="75" id="playerImage"></td>
<td width="156"><Pitcher ID="1770" TeamID="007" FirstName="Kyle " Lastname="Farnsworth" Inning="6" Outs="1" Throws="R" BBats="S" AB="1" BF="1"/> </td>
<td width="78" rowspan="4"><img src="BBLogo.png" name="imgawayteam" width="78" height="76" id="imgawayteam"></td>
</tr>
<tr>
<td class="PlayerName"><div align="center" id="PlayerName">Player Name</div></td>
</tr>
<tr>
<td><div align="center" class="GCPBP"></div></td>
</tr>
<tr>
<td class="PositionName"><div align="center" id="PositionName">Position Name</div></td>
</tr>
</table>
<table width="400" border="0">
<tr>
<td><div id="apDiv1"><img src="Images/Uniforms/umpire.gif" alt="" name="HPUmpire" width="11" height="30" id="HPUmpire"></div> <div id="apDiv2"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="C" width="11" height="30" id="C"></div> <div id="apDiv6"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="SB" width="11" height="30" id="SB"></div>
<div id="apDiv7"><img src="Images/Uniforms/umpire.gif" alt="" name="SBUmpire" width="11" height="30" id="SBUmpire"></div>
<div id="apDiv8"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="SS" width="11" height="30" id="SS"></div>
<div id="apDiv9"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="TB" width="11" height="30" id="TB"></div>
<div id="apDiv10"><img src="Images/Uniforms/umpire.gif" alt="" name="TBUmpire" width="11" height="30" id="TBUmpire"></div>
<div id="apDiv12"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="CF" width="11" height="30" id="CF"></div>
<div id="apDiv13"><img src="Images/Uniforms/040_unif_homeold.gif" alt="" name="RF" width="11" height="30" id="RF"></div>
<img src="http://images.sportsnetwork.com/mlb/attheballpark/stadiums/default.gif" name="imgStad" width="390" height="273" id="imgStad">
<div id="apDiv11"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="LF" width="11" height="30" id="LF"></div>
<div id="apDiv5"><img src="Images/Uniforms/umpire.gif" alt="" name="FBUmpire" width="11" height="30" id="FBUmpire"></div>
<div id="apDiv4"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="FB" width="11" height="30" id="FB"></div>
<div id="apDiv3"><img src="Images/Uniforms/040_unif_awayold.gif" alt="" name="P" width="11" height="30" id="P"></div>
</td>
</tr>
</table>
<p align="center"> </p>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p class="GCPBP"> </p>
<script>
var myVar = setInterval(myTimer,2000);
function myTimer()
{
//var d=new Date();
//var t=d.toLocaleTimeString();
//document.getElementById("demo").innerHTML=t;
loadAll();
}
</script>
</body>
</html>
This is the 2nd pitchers list not current pitcher this will pull Zack Wheller as pitcher and not current pitcher
<Pitcher ID="1770" TeamID="007" FirstName="Kyle " Lastname="Farnsworth" Inning="6" Outs="1" Throws="R" BBats="S" AB="1" BF="1"/>
$(d.find('Pitcher')).each(function(i, nodePlayer){ // always 1!
nodePlayer = $(nodePlayer);
var posItem = intPosID['P'];
if (posItem) { // && !posItem.updated
posItem.id = nodePlayer.attr('ID');
posItem.name = nodePlayer.attr('FirstName') + ' ' + nodePlayer.attr('Lastname');
posItem.updated = true;
//tempCount++;
}
});
41880.XMLfieldplayers.html
040-unif-home.gif
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is your birthday present to me. You never disappoint.Thank You.