Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JQUERY AND XML

Posted on 2013-02-06
10
Medium Priority
?
325 Views
Last Modified: 2013-11-19
I need to add a Table to the right of Image and text xml attributes hitting and season.
On the same row as the Image and text
How can I add Hitting these AB="4" R="0" H="0" RBI="0" DOUBLE="0" TRIPLE="0" HR="0"
and Season Season AB="472" H="115" R="70" BB="42" KO="71" CS="4" DOUBLE="25" TRIPLE="5" RBI="43" HR="14" to the right of my page with image and name is there anyway to add Hitting Attributes and Season Attributes.
http://www.powerzsoftware.com/lineup2.html
http://www.powerzsoftware.com/33661.XML

Please help my Boss is tough and he thinks this shit should be done in 5 minutes. The Dude that helped me out with this is awesome I added a CSS EFFECT to expand images. Check It out.
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
  • 6
  • 4
10 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38861770
Have a look here how your XML is structured

http://xmlgrid.net/

Load from URL and then you need the xPath that matches your needs
0
 

Author Comment

by:powerztom
ID: 38861799
Nice Tool nOT QUITE WHAT i WANT. could you write an XPATH STATEMENT FOR HITTING AND THEN TRY AND WRITE ONE FOR SEASON. pLease
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38861844
Why don't you start and we can help you fix any issues. You know your data better than we do
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:powerztom
ID: 38861977
Attached is how I need data retrieved and positioned
Pic1.png
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38863178
Here you go.

It is a little more than just answering questions...

Change
			li.appendChild(txt);
			document.getElementById("players").appendChild(li);

Open in new window

to
			li.appendChild(txt);
			getStats(players[i],li);
			document.getElementById("players").appendChild(li);

Open in new window

and add this
function getStats(player,li) {
  var hittingAttribs = ["AB","DOUBLE","TRIPLE"]; // fill in order
  var seasonAttribs = ["HR","DOUBLE","TRIPLE"]; // fill in order
  var hitting = player.getElementsByTagName("Hitting")[0];
  if (!hitting) {
  	  li.appendChild(document.createTextNode("- Not found")); // or nothing
  	  return;
  }
  var season = player.getElementsByTagName("Season")[0];
  if (!season) {
  	li.appendChild(document.createTextNode(" - Not found")); // or nothing
    return;
  }
  var txt = " Hitting: ";
  for (var i=0;i<hittingAttribs.length;i++) {
  	txt += hittingAttribs[i]+"="+hitting.getAttribute(hittingAttribs[i])+" ";
  }
  li.appendChild(document.createTextNode(txt));
  li.appendChild(document.createElement("br"));  	
  var bold = document.createElement("b");  	
  txt=" Season: ";
  for (var i=0;i<seasonAttribs.length;i++) {
  	txt += seasonAttribs[i]+"="+season.getAttribute(hittingAttribs[i]);
  }
  bold.appendChild(document.createTextNode(txt));
  li.appendChild(bold);
}

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 38863188
By the way, I did not use any jQuery.

If you want to use jQuery you should change all of the code to use it

function getStats(player,li) {
  var hittingAttribs = ["AB","DOUBLE","TRIPLE"]
  var seasonAttribs = ["HR","DOUBLE","TRIPLE"]
  var hitting = player.find("Hitting");
  if (!hitting) {
  	  li.append("- Not found");
  	  return;
  }
  var season = player.find("Season");
  if (!season) {
  	li.append("- Not found");
    return;
  }
  li.append(" Hitting: ");
  $.each(hittingAttribs,function(i, attrib) {
  	li.append(attrib+"="+hitting.attr(hittingAttribs[i])+" ");
  });
  li.append("<br/>");  	
  var bold = $("<b/>");  	
  bold.append(" Season: ");
  $.each(seasonAttribs,function(i, attrib) {
  	bold.append(attrib+"="+hitting.attr(hittingAttribs[i])+" ");
  });
  li.append(bold);
}
$(document).ready(function(){
  $.ajax({
    type: "GET",
    url: "33661.XML", 
    dataType: "xml",
    success: function(data){
        var players = $(data).find("Player");
	    var li="",txt="",img = "";
        $.each(players,function(i,player) {
        	player=$(player);
			li = $("<li/>");
			li.append($("<img/>").attr("src","http://images.sportsnetwork.com/MLB/attheballpark/players/" + player.attr("ID") + ".jpg"));
			txt = " " +
				player.attr("FirstName") + " " +
				player.attr("Lastname") + ", " +
				player.attr("Pos");
			li.append(txt);
			getStats(player,li);
			
			$("#players").append(li);
		
		});
	}
  });
});

Open in new window

0
 

Author Closing Comment

by:powerztom
ID: 38864034
Thanks for the code this really helps me moveon to the next phase. I cann't thankyou enough.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38864284
You are welcome.

If you need more help, feel free to contact me on the email in my profile
0
 

Author Comment

by:powerztom
ID: 38864756
Your Level of knowledge is amazing I'm going to be your best friend of the next few years. This project is evolving there are many more things that need to be created. I am a VB ASP.NET so JQUERY JAVA SCRIPT CSS3 is foreign to me.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38865061
:) I have been scripting since 1995 or so. You can be my friend :)

https://coderbits.com/mplungjan
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)

715 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