Solved

JQUERY AND XML

Posted on 2013-02-06
10
323 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

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 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help Creating PowerShell Script 4 66
Prevent certain words from being typed in a form 6 54
What is the best SEO Web Analytics tool/program 3 57
ReadyAPI 1.9.0 2 44
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to dynamically set the form action using jQuery.
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…

734 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