Jump to content

Tundra

Members
  • Content Count

    22
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Tundra

  • Rank
    Newbie
  1. Jesh, It doesnt look like im getting anywhere with this. Thanks for all the help though. <html><head><style type="text/css">table.roster { border: 0; cellpadding: 5; cellspacing: 1; background-color: #000000; text-align: center; font-size:11px; font-family:verdana;}table.roster td.01 { width: 40px; }table.roster td.02 { width: 80px;}table.roster td.03 { width: 80px;}table.roster tr.d1 { background-color: #999999; color: black;}table.roster tr.d2 { background-color: #cccccc; color: black;}</style></head><body><script type="text/javascript">var xmlDoc=null;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=336482");function GetPlayerObject(playerNode){ // Add error handling here to deal with empty nodes... var name = playerNode.getElementsByTagName("name")[0].childNodes[0].nodeValue; var rank = playerNode.getElementsByTagName("rank")[0].childNodes[0].nodeValue; var country = playerNode.getElementsByTagName("country")[0].childNodes[0].nodeValue; var favoriteRole = playerNode.getElementsByTagName("favoriteRole")[0].childNodes[0].nodeValue; var lastPlayed = playerNode.getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue; var playerLeaderboard = playerNode.getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue; var airLeaderboard = playerNode.getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue; var armorLeaderboard = playerNode.getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue; var infantryLeaderboard = playerNode.getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue; var supportLeaderboard = playerNode.getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue; var totalScore = playerNode.getElementsByTagName("totalScore")[0].childNodes[0].nodeValue; var numUnitsKilled = playerNode.getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue; var numUnitsLost = playerNode.getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue; // Build a player object using JSON. var player = { "name" : name, "rank" : rank, "country" : country, "favoriteRole" : favoriteRole, "lastPlayed" : lastPlayed, "playerLeaderboard" : playerLeaderboard, "airLeaderboard" : airLeaderboard, "armorLeaderboard" : armorLeaderboard, "infantryLeaderboard" : infantryLeaderboard, "supportLeaderboard" : supportLeaderboard, "totalScore" : totalScore, "numUnitsKilled" : numUnitsKilled, "numUnitsLost" : numUnitsLost, } return player;}function GetPlayerHtml(player)} // Using the JSON object passed, build out the HTML string var html = "<tr class='d1'>"; html += "<td class='02'>"; html += player.name; html += "</td>"; html += "<td class='01'>"; html += player.rank; html += "</td>"; html += "<td class='01'>"; html += player.country; html += "</td>"; html += "<td class='01'>"; html += player.favoriteRole; html += "</td>"; html += "<td class='02'>"; html += player.lastPlayed; html += "</td>"; html += "<td class='01'>"; html += player.playerLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.airLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.armorLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.infantryLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.supportLeaderboard; html += "</td>"; html += "<td class='02'>"; html += player.totalScore; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsKilled; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsLost; html += "</td>"; html += "</tr>"; // Return it to the caller return html;}var playerNodes = xmlDoc.getElementsByTagName("player");// Loop through all the player nodesfor (i=0; i < playerNodes.length; i++){ // Get the player JSON object var player = GetPlayerObject(playerNodes[i]); // Write out the HTML document.write(GetPlayerHtml(player));}</script></body></html>
  2. When I set off to help the World in Conflict gaming community come up with a way to display their clan's player's stats in a table I found W3schools. I quickly learned how to display the data using JS by reading the XML to HTML lesson in the XML Tutorial. I was amazed how fast I was able to come up with a table to display each player's stats as no one before was able to. Then I learned that if a player did not have a certain stat, particulary being ranked in a certain area like Air combat, the script would crash and nothing would print. So I started posting here in the forums for help. At first all I got was how sloppy my work was and a few other choice words. So with the exeption of Synook showing me how to make a node into an image (awesome btw) and Jesh with more great help on syntax, I have not been able to perfect my code or "clean it up" as everyone suggests. My sloppy code is the only one I have been able to make work.So basically all I am asking is to be pointed in the right direction as to what tutorial I should be reading. I want to start from scratch and produce a clean, efficient, and working project. I really appreciate everyone's help so far but the frustration and stress is really getting me down.My self-taught sloppy code that seems to work but crashes: <html><head><style type="text/css">table.roster { border: 0; cellpadding: 5; cellspacing: 1; background-color: #000000; text-align: center; font-size:11px; font-family:verdana;}table.roster td.01 { width: 40px; }table.roster td.02 { width: 80px;}table.roster td.03 { width: 80px;}table.roster tr.d1 { background-color: #999999; color: black;}table.roster tr.d2 { background-color: #cccccc; color: black;}</style></head><body><!--**********Start Column Header Table**********--><table class="roster"> <tr class="d2"> <td class="02">Callsign</td> <td class="01">Rank</td> <td class="01">Global</td> <td class="01">Air</td> <td class="01">Arm</td> <td class="01">Inf</td> <td class="01">Sup</td> <td class="03">Last Played</td> <td class="02">Total Score</td> <td class="01">Kills</td> <td class="01">Deaths</td> </tr></table><!--**********End Column Header Table**********--><!--XML Script NotesScript is Copyright 2008 Corey Dobbs (saturn_command@hotmail.com)You may use this code for free, just please keep these notes intactI am self taught and I know this code can be improved upon, please email me with any improvements!End XML Notes--><!--********************--><script type="text/javascript">var xmlDoc=null;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}<!--********************--><!--Start Tundra--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=336482");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d1'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}<!--********************--><!--Drako85--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=352899");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d2'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}<!--********************--><!--Nattis--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=347396");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d1'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}<!--********************--><!--ardisalis--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=355309");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d2'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}<!--********************--><!--ChurlishBrute--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=213069");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d1'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}<!--********************--><!--w1sp3r--><!--********************-->if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=226372");document.write("<table class='roster'>");var x=xmlDoc.getElementsByTagName("player");for (i=0;i<x.length;i++){ document.write("<tr class='d2'>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write("<img src=\"http://www.massgate.net/img/ranks/20px-" + x[i].getElementsByTagName("rank")[0].childNodes[0].nodeValue + ".png\" />");document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='03'>");document.write(x[i].getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='02'>");document.write(x[i].getElementsByTagName("totalScore")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue);document.write("</td>");document.write("<td class='01'>");document.write(x[i].getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue);document.write("</td>");document.write("</tr>");}document.write("</table>");}</script></body></html> Attempt to clean it up (provided by Jesh): <html><head><style type="text/css">table.roster { border: 0; cellpadding: 5; cellspacing: 1; background-color: #000000; text-align: center; font-size:11px; font-family:verdana;}table.roster td.01 { width: 40px; }table.roster td.02 { width: 80px;}table.roster td.03 { width: 80px;}table.roster tr.d1 { background-color: #999999; color: black;}table.roster tr.d2 { background-color: #cccccc; color: black;}</style></head><body><script type="text/javascript">var xmlDoc=null;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=336482");function GetPlayerObject(playerNode){ // Add error handling here to deal with empty nodes... var name = playerNode.getElementsByTagName("name")[0].childNodes[0].nodeValue; var rank = playerNode.getElementsByTagName("rank")[0].childNodes[0].nodeValue; var country = playerNode.getElementsByTagName("country")[0].childNodes[0].nodeValue; var favoriteRole = playerNode.getElementsByTagName("favoriteRole")[0].childNodes[0].nodeValue; var lastPlayed = playerNode.getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue; var playerLeaderboard = playerNode.getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue; var airLeaderboard = playerNode.getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue; var armorLeaderboard = playerNode.getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue; var infantryLeaderboard = playerNode.getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue; var supportLeaderboard = playerNode.getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue; var totalScore = playerNode.getElementsByTagName("totalScore")[0].childNodes[0].nodeValue; var numUnitsKilled = playerNode.getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue; var numUnitsLost = playerNode.getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue; // Build a player object using JSON. var player = { "name" : name, "rank" : rank, "country" : country, "favoriteRole" : favoriteRole, "lastPlayed" : lastPlayed, "playerLeaderboard" : playerLeaderboard, "airLeaderboard" : airLeaderboard, "armorLeaderboard" : armorLeaderboard, "infantryLeaderboard" : infantryLeaderboard, "supportLeaderboard" : supportLeaderboard, "totalScore" : totalScore, "numUnitsKilled" : numUnitsKilled, "numUnitsLost" : numUnitsLost, } return player;}function GetPlayerHtml(player)} // Using the JSON object passed, build out the HTML string var html = "<tr class='d1'>"; html += "<td class='02'>"; html += player.name; html += "</td>"; html += "<td class='01'>"; html += player.rank; html += "</td>"; html += "<td class='02'>"; html += player.country; html += "</td>"; html += "<td class='01'>"; html += player.favoriteRole; html += "</td>"; html += "<td class='02'>"; html += player.lastPlayed; html += "</td>"; html += "<td class='01'>"; html += player.playerLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.airLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.armorLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.infantryLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.supportLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.totalScore; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsKilled; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsLost; html += "</td>"; html += "</tr>"; // Return it to the caller return html;}var playerNodes = xmlDoc.getElementsByTagName("player");</script></body></html> Thanks again...
  3. Arrg!!How do you make your code display into a smaller box like you guys, i dont see a button anywhere!
  4. This really confuses me... 1. I can't find JSON anywhere on W3Schools website. 2. Where do I tell it to actually print anything? 3. What error handling are you refering to?4. Here is what I came up with: <html><head><style type="text/css">table.roster { border: 0; cellpadding: 5; cellspacing: 1; background-color: #000000; text-align: center; font-size:11px; font-family:verdana;}table.roster td.01 { width: 40px; }table.roster td.02 { width: 80px;}table.roster td.03 { width: 80px;}table.roster tr.d1 { background-color: #999999; color: black;}table.roster tr.d2 { background-color: #cccccc; color: black;}</style></head><body><script type="text/javascript">var xmlDoc=null;if (window.ActiveXObject){// code for IExmlDoc=new ActiveXObject("Microsoft.XMLDOM");}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.xmlDoc=document.implementation.createDocument("","",null);}else{alert('Your browser cannot handle this script');}if (xmlDoc!=null){xmlDoc.async=false;xmlDoc.load("http://www.massgate.net/xml-player.php?id=336482");function GetPlayerObject(playerNode){ // Add error handling here to deal with empty nodes... var name = playerNode.getElementsByTagName("name")[0].childNodes[0].nodeValue; var rank = playerNode.getElementsByTagName("rank")[0].childNodes[0].nodeValue; var country = playerNode.getElementsByTagName("country")[0].childNodes[0].nodeValue; var favoriteRole = playerNode.getElementsByTagName("favoriteRole")[0].childNodes[0].nodeValue; var lastPlayed = playerNode.getElementsByTagName("lastPlayed")[0].childNodes[0].nodeValue; var playerLeaderboard = playerNode.getElementsByTagName("playerLeaderboard")[0].childNodes[0].nodeValue; var airLeaderboard = playerNode.getElementsByTagName("airLeaderboard")[0].childNodes[0].nodeValue; var armorLeaderboard = playerNode.getElementsByTagName("armorLeaderboard")[0].childNodes[0].nodeValue; var infantryLeaderboard = playerNode.getElementsByTagName("infantryLeaderboard")[0].childNodes[0].nodeValue; var supportLeaderboard = playerNode.getElementsByTagName("supportLeaderboard")[0].childNodes[0].nodeValue; var totalScore = playerNode.getElementsByTagName("totalScore")[0].childNodes[0].nodeValue; var numUnitsKilled = playerNode.getElementsByTagName("numUnitsKilled")[0].childNodes[0].nodeValue; var numUnitsLost = playerNode.getElementsByTagName("numUnitsLost")[0].childNodes[0].nodeValue; // Build a player object using JSON. var player = { "name" : name, "rank" : rank, "country" : country, "favoriteRole" : favoriteRole, "lastPlayed" : lastPlayed, "playerLeaderboard" : playerLeaderboard, "airLeaderboard" : airLeaderboard, "armorLeaderboard" : armorLeaderboard, "infantryLeaderboard" : infantryLeaderboard, "supportLeaderboard" : supportLeaderboard, "totalScore" : totalScore, "numUnitsKilled" : numUnitsKilled, "numUnitsLost" : numUnitsLost, } return player;}function GetPlayerHtml(player)} // Using the JSON object passed, build out the HTML string var html = "<tr class='d1'>"; html += "<td class='02'>"; html += player.name; html += "</td>"; html += "<td class='01'>"; html += player.rank; html += "</td>"; html += "<td class='02'>"; html += player.country; html += "</td>"; html += "<td class='01'>"; html += player.favoriteRole; html += "</td>"; html += "<td class='02'>"; html += player.lastPlayed; html += "</td>"; html += "<td class='01'>"; html += player.playerLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.airLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.armorLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.infantryLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.supportLeaderboard; html += "</td>"; html += "<td class='01'>"; html += player.totalScore; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsKilled; html += "</td>"; html += "<td class='01'>"; html += player.numUnitsLost; html += "</td>"; html += "</tr>"; // Return it to the caller return html;}var playerNodes = xmlDoc.getElementsByTagName("player");</script></body></html>
  5. This looks like it should work but I may be messing it up by forcing it into my script table: document.write("<td class='01'>");var parentNode = document.getElementsByTagName("player")[0];var killedNode = parentNode.getElementsByTagName("numUnitsKilled")[0];var lostNode = parentNode.getElementsByTagName("numUnitsLost")[0];var numUnitsKilled = 0;var numUnitsLost = 0;if(killedNode && killedNode.nodeValue != "" && isNaN(killedNode.nodeValue) == false){ numUnitsKilled = Number(killedNode.nodeValue);}if(lostNode && lostNode.nodeValue != "" && isNaN(lostNode.nodeValue) == false){ numUnitsLost = Number(lostNode.nodeValue);}if(numUnitsLost > 0){ document.write(numUnitsKilled / numUnitsLost);}document.write("</td>"); Do you see anything wrong with doing that? Right now it doesnt work, just prints a blank cell.Thanks again!
  6. I've been studying JS but cant find how to use JS to divide two numbers....
  7. thanks a lot, i will give that a try.I really appreciate your help!
  8. Oh and BTW my code works, it may be sloppy but it works. The only problem is the crash if an element becomes null.
  9. You sir are a f-ing Genius!!!! It worked the first time! I really need help with the rest of my project if you would be so kind to lend your genius again.
  10. Thanks for the code. I'll try it out.
  11. Aww come on, I tried really hard and I impressed myself. Well I will learn XSLT and PHP's DOM and get back with you.
  12. Bump,boen_robot this is my biggest problem as of today, its the only major hurtle holding me back from publishing my code.Thanks again!
  13. Please see my entire code here:http://w3schools.invisionzone.com/index.php?showtopic=17947Thanks!
  14. Yes they are all on the same domain and have identical elements.I managed to figure out how to do it but now i have the loop crash problem because one or more of my feeds had an empty element.Thanks for responding
×
×
  • Create New...