Solved

reading xml stop at first value

Posted on 2013-11-12
2
339 Views
Last Modified: 2013-11-12
I have a xml sheet and I wrote bsome code and it runs and retrieve's the last xml player's values I know this exists but not sure how to code it to stop on the first xml player node. The one that is outside the two teams I think the code I wrote justs flies right over the whole xml doc.

function loadData() {
 $.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameID + ".xml",
                    dataType: "xml",
                    success: function (data) {
                        var d = $(data);
						 var Play = d.find('Play');
                      //  d.find('Team').each(function (i, Team) {
                         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 = $(data).find("Player");     
                             $.each(players,function(i,player) {
            player=$(player);
        var tid = player.attr('TeamID');
         var pid =  player.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 = " " +
                player.attr("FirstName") + " " +
                player.attr("Lastname") + ", " +
                player.attr("Pos");
           // getStats(player,txt,img,li);
            $('#txtpts').html(player.attr("Points"));
          //  $("#players").append(li);
			$('txtassists').html(player.attr("Assists"));
         
        });

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

Open in new window

Please show me what I did wrong and correct syntax. Thanks EE

THIS IS WHAT i'M AFTER  Michael Carter-Williams   < 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"/>
Court.html
18672.XML
0
Comment
Question by:powerztom
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39642918
I don't see any player outside the two teams. wrong XML sample? Could you provide a good one?
xml
As you know jQuery.each is to loop over an array
I see two loops :

$("items:eq(0)") provide the first item of the items collection
$("items:first") provide the first item of the items collection
$("items:last") provide the last item of the items collection
0
 

Author Closing Comment

by:powerztom
ID: 39642992
Thanks for telling me about each It's the 18672.XML attached above and it's players node in the beginning just after the linescore. I tried :first but I didn't get it You got a hockey xml file this one is for basketball it's
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

749 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