Repeating xml values

I am working on a Hockey gamecast and I am getting duplicate values. For example the two teams are Calgary Flames and Anaheim Ducks. Calgary is the Home team and Anaheim is the away team. When I make a call to see who is away I am getting the Hometeam' values in two spots the xml Attribute name and Fullname. I have a feeling that my code is reading away xml values and then it is being overwritten by Home team values. But oddly enough that correct team logo is coming up for the away team.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sports Network</title>
<style type="text/css">
.TOPALIGN {
	text-align: center;
	vertical-align: top;
}
.sizescore {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 25px;
	font-style: normal;
	font-weight: bold;
	color: #000;
}
.cellcolor {
	color: #F5F4D6;
}
.cellcolor td {
	color: #F8F5AD;
}
</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 myVar = setInterval(loadData, 1000);
var xmlPath ='.' //'/xml/nhl/scores/real';
var xmlGameID = '16937'; 
$(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 id = team.attr("ID").toLowerCase();
                var teamname = team.attr("name");
               
                var d = $(data);
                d.find('Team').each(function(i,Team){
                    if ($(Team).attr('vh') == "H") {

                        $('#imghome').attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/'+$(Team).attr('ID')+".png");

                    }
					var Hometeam =$(Team).attr('Fullname');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtHometeam').html(Hometeam);
					 var txtHome1 =$(Team).attr('name');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtHome').html(txtHome1);
					
                })
				 var d = $(data);
                d.find('Team').each(function(i,Team){
                    if ($(Team).attr('vh') == "A") {

                        $('#imgaway').attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/'+$(Team).attr('ID')+".png");

                    }
					// var VS1 = $(Team).find('Linescore');
					 var Awayteam =$(Team).attr('Fullname');
					 $('#txtAwayteam').html(Awayteam);
					 var txtAway1 =$(Team).attr('name');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtAway').html(txtAway1);
       
                });
            });
        } 
    });
});


</script>
</head>

<body>
<table width="700" border="0">
  
    <td width="224"><table width="100%" border="0">
      <tr>
        <td width="36%" height="59"><img src="http://199.233.14.112/aspdata/nhl2/IMAGES/Defaultlogo.png" name="imgaway" width="75" height="75" id="imgaway"></td>
        <td width="43%"><p class="TOPALIGN" id="txtAwayteam">AwayTeam</p>
          <p>&nbsp;</p></td>
        <td width="21%"><p class="TOPALIGN sizescore"><strong id="awayteamscore">0</strong></p>
          </td>
      </tr>
    </table>
      <table width="100%" border="0">
        <tr>
          <td width="23%"><div align="center">Shots</div></td>
          <td width="35%"><div align="center">FaceOff %</div></td>
          <td width="16%"><div align="center">Hits</div></td>
          <td width="26%"><div align="center">Penalties</div></td>
        </tr>
        <tr class="cellcolor">
          <td><div align="center" class="cellcolor" id="awayShots"></div></td>
          <td><div align="center" id="awayFO"></div></td>
          <td><div align="center" id="awayHits"></div></td>
          <td><div align="center" id="awayPenalties"></div></td>
        </tr>
      </table></td>
    <td width="214" class="TOPALIGN"><table width="100%" border="0">
      <tr>
        <td><div align="center"><span class="TOPALIGN">Period</span></div></td>
        <td><div align="center"><span class="TOPALIGN">Time Remaining</span></div></td>
      </tr>
      <tr>
        <td id="txtPeriod"><div align="center" id="txtPeriod"></div></td>
        <td class="TOPALIGN"><div align="center" id="txtTime"></div></td>
      </tr>
    </table>
      <table width="100%" border="1">
        <tr>
          <td width="50%">&nbsp;</td>
          <td width="12%">1</td>
          <td width="14%">2</td>
          <td width="12%">3</td>
          <td width="12%" id="overtime">OT</td>
        </tr>
        <tr>
          <td><div align="center" id="txtAway">Visitor</div></td>
          <td><div align="center" id="period1V"></div></td>
          <td><div align="center" id="period2V"></div></td>
          <td><div align="center" id="periodV3"></div></td>
          <td><div align="center" id="periodv4"></div></td>
        </tr>
        <tr>
          <td><div align="center" id="txtHome">Home</div></td>
          <td><div align="center" id="periodH1"></div></td>
          <td><div align="center" id="peroidH2"></div></td>
          <td><div align="center" id="periodH3"></div></td>
          <td><div align="center" id="peroidH4"></div></td>
        </tr>
      </table></td>
    <td width="248" class="TOPALIGN"><table width="100%" border="0">
      <tr>
        <td width="32%"><img src="http://199.233.14.112/aspdata/nhl2/IMAGES/Defaultlogo.png" alt="" name="imghome" width="75" height="75" id="imghome"></td>
        <td width="42%" class="TOPALIGN" id="txtHometeam">HomeTeam</td>
        <td width="26%"><p class="TOPALIGN"><strong class="TOPALIGN sizescore" id="hometeamscore">0</strong></p>
          <p>&nbsp;</p></td>
      </tr>
    </table>
      <table width="100%" border="0">
        <tr>
          <td width="28%"><div align="center">Shots</div></td>
          <td width="29%"><div align="center">FaceOff %</div></td>
          <td width="18%"><div align="center">Hits</div></td>
          <td width="25%"><div align="center">Penalties</div></td>
        </tr>
        <tr>
          <td><div align="center" id="homeShots"></div></td>
          <td><div align="center" id="homeFO"></div></td>
          <td><div align="center" id="homeHits"></div></td>
          <td><div align="center" id="homepenalties"></div></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>

Open in new window

Please Help EE Thanks

Take a look
http://199.233.14.112/aspdata/nhl2/ScoreBoard.html
hOCKEY.zip
powerztomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
You have a loop with two identical loops nested inside it:

d.find('Team').each(function(i,Team){
    ...
    d.find('Team').each(function(i,Team){
        ....
    });
    d.find('Team').each(function(i,Team){
        ....
    });
});

So the inner loops will run multiple times because of the outer loop. In this case since there are two teams, the outer loop runs two times and each of the inner loops two times then two times again.

Why not do all you need to do inside the first loop?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
powerztomAuthor Commented:
TommyBoy, Are you a Chris Farley fan ?

Can you just show me proper closing brackets before I accept and Thanks man. I just sometimes have a problem closing brackets.

$(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 id = team.attr("ID").toLowerCase();
               // var teamname = team.attr("name");
                var d = $(data);
                
                    if ($(Team).attr('vh') == "A") {

                        $('#imgaway').attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/'+$(Team).attr('ID')+".png");

                    }
					// var VS1 = $(Team).find('Linescore');
					 var Awayteam =$(Team).attr('Fullname');
					 $('#txtAwayteam').html(Awayteam);
					 var txtAway1 =$(Team).attr('name');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtAway').html(txtAway1);
               
                    if ($(Team).attr('vh') == "H") {

                        $('#imghome').attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/'+$(Team).attr('ID')+".png");

                    }
					var Hometeam =$(Team).attr('Fullname');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtHometeam').html(Hometeam);
					 var txtHome1 =$(Team).attr('name');
					// $('#txtHometeam').html(Hometeam);
					 $('#txtHome').html(txtHome1);
					 //var HS1 = $(Team).find('Linescore');
         // var hs2 = HS1.attr('Score');
         // $('#HS').html(HS1.attr('Score')); 
			 });
			}
			}
			 });
			
			 }  
  //ajax
});
  }

Open in new window

0
powerztomAuthor Commented:
Tommy Boy spotted what was wrong and explained what to do to fix it.Nice work.
0
Tom BeckCommented:
Sorry, I was in the middle of something and could not respond quickly. Thanks for the points.

Chris Farley -- interesting character -- idolized and mimicked the career and habits of John Belushi to the point of dying at the same age (33) and from the same stupidity; heroin and cocaine overdose.

But he was entertaining.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.