Solved

Retrieving xml data

Posted on 2014-01-15
4
299 Views
Last Modified: 2014-01-16
I have one team out of a hold league roster with stats. If I can get one right I can duplicate this and use it for every other team I have alot of xml code to reference And I am getting better at handling xml. But of course I also run into the issUE i GOT NOW XML is laid out different from my samples To start I can't even get out of the starting Gate I start off with top attrib called message and need to strip Image with teamid and title. Then I was going to do the players stats and then clone. But I using Fire Bug and I can't get intro data.

What is wrong?

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<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/nba/scores/real';
        var xmlGameID = 'ADX-INDSTATS-PHI'; 
$(document).ready(function(){
			$.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameID + ".xml",
                    dataType: "xml",
                    success: function (data) {
                        var d = $(data);
						 var message = d.find('message');
						 var title = message.attr('Title');
						 var teamid = message.attr('TeamID');
			$('title1').text(title);
			 $('teamid1').attr('src', 'http://images.sportsnetwork.com/NHL/attherink/players/' + teamid + '.png');
			
			
			 }
			 
        });
					
                   
                //    }
             //   });	
	 });
function getsimple() {
$.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameID + ".xml",
                    dataType: "xml",
                    success: function (data) {
                        var d = $(data);
						 var message = d.find('message');
						 var title = message.attr('Title');
						 var teamid = message.attr('TeamID');
			$('title1').text(title);
			 $('teamid1').attr('src', 'http://images.sportsnetwork.com/NHL/attherink/players/' + teamid + '.png');
			
			
			 }
			 
        });	
}
	 	
</script>
</head>

<body>
<table width="400" border="0">
  <tr>
    <td width="124"><div align="center" id="teamid1"></div></td>
    <td width="266"><div align="center" id="title1"></div></td>
  </tr>
</table>

</body>

</html>

Open in new window


  As you can see I can't get started Why?
Flyers.html
ADX-INDSTATS-PHI.xml
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
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39782919
work for me :

You mainly forget the # to select element by their id :
$('#title1') and not $('title1')

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<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/nba/scores/real';
	var xmlGameID = 'ADX-INDSTATS-PHI'; 

	$(document).ready(function() {
		var myVar = setInterval(getsimple, 10000);
		getsimple();
	});

	function getsimple() {
		$.get(xmlPath + "/" + xmlGameID + ".xml", function(data) {
			var d = $(data);
			var message = d.find('message');
			var title = $("Title", message).text();
			var teamid = $("TeamID", message).text();
			$('#title1').text(title);
			$('#teamid1').attr('src', 'http://images.sportsnetwork.com/NHL/attherink/players/' + teamid + '.png');
		});
	}

</script>
</head>

<body>
<table width="400" border="0">
  <tr>
    <td width="124"><div align="center" id="teamid1"></div></td>
    <td width="266"><div align="center" id="title1"></div></td>
  </tr>
</table>
</body>
</html>

Open in new window

0
 

Author Comment

by:powerztom
ID: 39783176
This is what I see no Flyer's logotHANKS BUT NO TEAM LOGO IS COMING UP I CHANGED THE IMAGE PATH CAUSE IT WAS POINTING TOWARD PLAYERS IMAGES INSTEAD OF TEAM'S LOGO ANY IDEAS? IN FIREBUG teamid is retrieving the team id . Please  leakim971

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<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/nba/scores/real';
	var xmlGameID = 'ADX-INDSTATS-PHI'; 

	$(document).ready(function() {
		var myVar = setInterval(getsimple, 10000);
		getsimple();
	});

	function getsimple() {
		$.get(xmlPath + "/" + xmlGameID + ".xml", function(data) {
			var d = $(data);
			var message = d.find('message');
			var title = $("Title", message).text();
			var teamid = $("TeamID", message).text();
			$('#title1').text(title);
			$('#teamid1').attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/' + teamid + '.png');
		});
	}

</script>
</head>

<body>
<table width="400" border="0">
  <tr>
    <td width="124"><div align="center" id="teamid1"></div></td>
    <td width="266"><div align="center" id="title1"></div></td>
  </tr>
</table>

</body>
</html>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39783565
teamid1 is a DIV, why should it dislay a logo? Because you set it's "src" attribute?
<div align="center" id="teamid1"></div>
should be :
<div align="center"><img src="default_logo.jpg" alt="team logo" id="teamid1" /></div>

So I got :
http://images.sportsnetwork.com/NHL/attherink/players/134.png

But it's not found...

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<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/nba/scores/real';
	var xmlGameID = 'ADX-INDSTATS-PHI'; 

	$(document).ready(function() {
		var myVar = setInterval(getsimple, 10000);
		getsimple();
	});

	function getsimple() {
		$.get(xmlPath + "/" + xmlGameID + ".xml", function(data) {
			var d = $(data);
			var message = d.find('message');
			var title = $("Title", message).text();
			var teamid = $("TeamID", message).text();
			$('#title1').text(title);
			$('#teamid1').attr('src', 'http://images.sportsnetwork.com/NHL/attherink/players/' + teamid + '.png');
		});
	}

</script>
</head>

<body>
<table width="400" border="0">
  <tr>
    <td width="124"><div align="center" id="teamid1"></div></td>
    <td width="266"><div align="center"><img src="default_logo.jpg" alt="team logo" [b]id="teamid1"[/b] /></div></td>
  </tr>
</table>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:powerztom
ID: 39785462
leakim971 Thanks you pointed me in the right direction. I make newbie mistakes like
teamid1 is a DIV, why should it dislay a logo? Because you set it's "src" attribute?

I used a team logo and viewed the page and there it was the Flyers Logo. Now I'm out of the starting gate running.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
boostsrap 1 32
CSS Formatting Getting Stripped 1 35
object method as an event handler 8 73
What is the valid CSS Selector Chain for this situation? 3 17
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
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…

739 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