April 28th, 2013, 06:01 PM
-
Javascript Code to allow XML Feed to appear on webpage!!!
Hello all,
I have tried so many things to get this to work but to no avail, can someon eplease help me out here with a simple script for n XML steam feed.
URL IN TWO BITS BELOW
http
://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=221380&format=xml
OK NOW THE ISSUE IS:
I have a blank webpage which I have placed the above link into, I simply want the contents of the XML feed from the link to appear in my
page.......
How do I make the contents of that url appear on the same page??
SO I NEED THE SMALL SCRIPT OR HTML CODE TO DO THIS
Also I would like to have the background a certain colour and use a certain font like 12point arial with bold headings and lower case text.
Can someone please provide me with the html to allow this XML feed to appear on my webpage with a different colour background, arial 12pt font in
bold and lowercase
____________________________________________________________________________
I RECEIVED A REPLY TO THIS POST AND THEY ADDED THIS:
It's a little hard to tell from what you wrote. But, I think what you are looking for is an AJAX script to pull in the XML,
then CSS can take care of the formatting.
Look up how to process a XMLHttpRequest in javascript (or another scripting language). That will let you put the XML file into an array. Then,
you can use (javascript) document.write() to put the pieces on your page.
______________________________________________________________________________
SO this being said do I need a javascript code in the page to show the XML Feed with formatting, what would this code be, this is the magical
question

Could someone please please help me..........
With regards
Mathew
April 29th, 2013, 07:58 PM
-
You can scrape the feed with a server side language. Then you can turn the scraped content into JavaScript and use JavaScript's global split() function, to separate your XML tags (the innerText of those tags) and add them into a dynamic array. Then set-up your JavaScript to display each of the array keys, from the dynamic array and display them accordingly.
April 29th, 2013, 08:18 PM
-
Originally Posted by web_loone08
You can scrape the feed with a server side language. Then you can turn the scraped content into JavaScript and use JavaScript's global split() function, to separate your XML tags (the innerText of those tags) and add them into a dynamic array. Then set-up your JavaScript to display each of the array keys, from the dynamic array and display them accordingly.
Hi web_loone08, many thanks for this indeed, I really appreciate you responding to me, all of this sounds excellent and I would love to implement this. The issue I have is that all of this is Greek to me and I have made many attempts to get some help on this, by posting the same question in many forums.....the saddest part about all of this is I have no clue about the code, and yes ultimately I am asking someone to help me with the actual code I stick into the page and walla.....
I am sorry I have tried so many scripts, whenever I see a script that looks like it, I try it and it doesn't work I have tried everything short of learning the language and doing a course, I am sorry that this is not possible for me hence why I am posting all over the place for someone to help.
If someone asked me aoubt helping them on something I know I would be more than happy to help them. I guess I dont have the boldness to ask can someone please give me the code I need. I guess I am now asking this question. Again thank you very much for replying to my question, even though its not the answer I need I do greatly appreciate you responding
With regards
April 29th, 2013, 08:36 PM
-
If your trying to add something like this to a web page and you know nothing about client side/server side languages; nor do you intend on learning; you have about two choices: hire a web developer or look into "Feed2HTML APIs". The latter..., is probably your best bet.
April 29th, 2013, 08:44 PM
-
Hello there, thank you so very much, I am going to give this a crack and see how it goes, again thank you so very much for this, greatly appreciated
Cheers
April 29th, 2013, 08:46 PM
-
Look into this Google Feed API; I think this could help you out quit well. Your welcome and good luck.
April 29th, 2013, 08:51 PM
-
Ok, I will look into that also, again thank you...you have been so kind
Cheers mate
April 29th, 2013, 11:20 PM
-
I still think the simplest solution is loading the XML as an Ajax request. 10-12 lines of javascript, no API, no server side scripting needed, dozens of examples on the web.
Comments on this post
April 29th, 2013, 11:40 PM
-
Hi there,
i am getting so frustrated, I dont know why but nothing is working, yes I was after something simple to display the contents of the url in the page
I never thought it was trying to find a needle in a haystack, ok I will start trying to find something along the lines of
XML as an Ajax request
Many many many thanks
April 30th, 2013, 01:11 PM
-
If you know nothing about JavaScript and/or you do not want to learn; your not going to be able/want to conceive the concepts of XML to AJAX; unless you try to learn these concepts. So that's why the Google Feed API is so simple for you. What did you not understand? It gives you samples and instructions on how to implement the API.
-
VERY SORRY FOR THIS BUT JUST AN UPDATE, OK THIS IS WHERE I AM AT NOW, TRYING TO DO THE FOLLOWING:
Page is found here BTW:
http://www.mdexter.com/aoe2hdozclan.com/rankings1.php
1 . Remove errors, some name entries have errors and an error that comes up with the following:
Warning: DOMDocument::load() [domdocument.load]: Document is empty in http://steamcommunit...085870722?xml=1, line: 1 in /home/mp/public_html/aoe2hdozclan.com/test.php on line 78
The line in question is:
PHP Code:
isset($friendsOf) ? $friendsOf.'/' : ''
).'?xml=1&start=' . $start . '&end=' . $end,
LIBXML_NOBLANKS || LIBXML_NOCDATA
)) {
$entries = $feed->getElementsByTagName('entries');
if ($entries->length>0) {
THE LINE IN QUESTION IS THIS: )) {
which I have a temp fix using:
// Turn off all error reporting
error_reporting(0);
2. Change where avatar is and move it to where rating is, and move rating and rank to the right, and REMOVE UGCID alltogether
3. Add the avatarMedium from xml details below which adds an avatar image to the avatar column, details of parser found here:
PHP Code:
<profile>
<steamID64>76561197963686471</steamID64>
<steamID>-Dare Devil/x/</steamID>
<onlineState>offline</onlineState>
<stateMessage>Last Online: 2 hrs, 33 mins ago</stateMessage>
<privacyState>public</privacyState>
<visibilityState>3</visibilityState>
−
<avatarIcon>
http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96.jpg
</avatarIcon>
−
<avatarMedium>
http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96_medium.jpg
</avatarMedium>
−
<avatarFull>
http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96_full.jpg
</avatarFull>
<vacBanned>0</vacBanned>
<tradeBanState>None</tradeBanState>
<isLimitedAccount>0</isLimitedAccount>
<customURL>jsmucha</customURL>
<memberSince>January 1, 2004</memberSince>
<steamRating>10</steamRating>
<hoursPlayed2Wk>69.7</hoursPlayed2Wk>
<headline></headline>
<location>Danbury, Connecticut, United States</location>
<realname></realname>
<summary>I like dragons. And zombies.</summary>
−
<mostPlayedGames>
−
<mostPlayedGame>
<gameName>Age of Empires II: HD Edition</gameName>
<gameLink>http://steamcommunity.com/app/221380</gameLink>
−
<gameIcon>
http://media.steampowered.com/steamcommunity/public/images/apps/221380/109c74df17f9b67ea47d8f01e3d1ec25278b9f73.jpg
</gameIcon>
−
<gameLogo>
http://media.steampowered.com/steamcommunity/public/images/apps/221380/37e9da3f1174891fe38f8fb0206acda8b6bfc729.jpg
</gameLogo>
−
<gameLogoSmall>
http://media.steampowered.com/steamcommunity/public/images/apps/221380/37e9da3f1174891fe38f8fb0206acda8b6bfc729_thumb.jpg
</gameLogoSmall>
<hoursPlayed>58.1</hoursPlayed>
<hoursOnRecord>110</hoursOnRecord>
<statsName>AgeofEmpiresIIHDEdition</statsName>
The item to parse and create the avatar is: <avatarMedium>
And that is it for now I have tried so many types of scripts etc but I am coming up short, ok the full script of the page is below:
PHP Code:
<?php
// Turn off all error reporting
error_reporting(0);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
/*
I limited it to ten because it takes so long to pull every user's
profile! I suggest setting up some sort
of caching or daily updates
if deploying this live.
*/
$start = 1;
$end = 40;
$friendsOf = 133447;
$game = 'AgeofEmpiresIIHDEdition';
$feed = new DOMDocument();
if ($feed->load(
'http://steamcommunity.com/stats/' . $game . '/leaderboards/'.(
isset($friendsOf) ? $friendsOf.'/' : ''
).'?xml=1&start=' . $start . '&end=' . $end,
LIBXML_NOBLANKS || LIBXML_NOCDATA
)) {
$entries = $feed->getElementsByTagName('entries');
if ($entries->length>0) {
$entries = $entries->item(0)->getElementsByTagName('entry');
if ($entries->length>0) {
echo '
<table id="leaderBoard">
<caption>Age of Empires II HD Leaderboard</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Rating</th>
<th scope="col">Rank</th>
<th scope="col">UGCID</th>
<th scope="col">Avatar</th>
</tr>
<style>
table, th
body {
font-family:Verdana, Arial, Helvetica;
font-size: 110%;
padding-left: 15px;
margin: 0px;
color: #825a15;
font-weight:bold;
}
th, td
{
border:1px solid black;
}
td, th
{
background-color:ebcc9b;
}
th, td
{
padding-right: 15px;
}
th
{
padding-left: 15px;
}
</style>
</thead><tbody>';
foreach ($entries as $entry) {
$data = $entry->firstChild;
$user = new DOMDocument;
if ($user->load(
'http://steamcommunity.com/profiles/' . $data->nodeValue . '?xml=1',
LIBXML_NOBLANKS || LIBXML_NOCDATA
)) {
$userName = $user->getElementsByTagName('steamID')->item(0)->nodeValue;
// note ALL user data is available here
} else $userName = '<strong>ERROR</strong>';
echo '
<tr>
<th scope="row">', $userName, '</th>';
while ($data = $data->nextSibling) echo '
<td>', $data->nodeValue, '</td>';
echo '
</tr>';
} // foreach $entries
echo '
</tbody>
</table>';
} else echo '<p>no entries found in entry
table</p>';
} else echo '<p>no entries table found</p>';
} else echo '<p>unable to load feed</p>';
?>
<?php
// Do some form processing here
echo '<a href="rankings2.php" font="Arial" style="color: #7d4417">next</a>';
?>
-
hello irene, your images are just broken, im just getting one purple faced ecomotion ??
-
Originally Posted by aoe2hdozclan
hello irene, your images are just broken, im just getting one purple faced ecomotion ??
When you see that, that is someone posting cloaked affiliate links.
I've deleted Irene's posts.
-
ahh ok, many thanks kravvitz