Web Analytics Made Easy -
StatCounter Adding bits from an XML feed to a website? - CodingForum

Announcement

Collapse
No announcement yet.

Adding bits from an XML feed to a website?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding bits from an XML feed to a website?

    Howdy all.

    I've been going nuts trying to figure this out. I'm still a novice at coding, so I figured I'd turn to the masters.

    I play a MMO called "City of Heroes." Some people created an XML feed of the the games server status. They are allowing anyone to use the feed on their website and said that users can modify the XML feed to add/remove servers that you do not wish to show on your website.

    The snag is that I'm not sure how to do it and the creators of the XML feed have gone missing and haven't returned my email.

    So I ask you all for help as my website needs this feed and my re-launch is in two days.

    This is the XML feed: http://sgspaces.net/server_status/srvstat.xml

    The XML shows the following:

    Code:
    <?xml version="1.0" encoding="iso-8859-1" ?> 
    - <servers timestamp="2011-09-11 13:20:18" timezone="UTC">
      <server name="Live Login" status="Up" /> 
      <server name="Freedom" status="Up" /> 
      <server name="Justice" status="Up" /> 
      <server name="Pinnacle" status="Up" /> 
      <server name="Virtue" status="Up" /> 
      <server name="Liberty" status="Up" /> 
      <server name="Guardian" status="Up" /> 
      <server name="Infinity" status="Up" /> 
      <server name="Protector" status="Up" /> 
      <server name="Victory" status="Up" /> 
      <server name="Champion" status="Up" /> 
      <server name="Triumph" status="Up" /> 
      <server name="Union" status="Up" /> 
      <server name="Defiant" status="Up" /> 
      <server name="Zukunft" status="Up" /> 
      <server name="Vigilance" status="Up" /> 
      <server name="Test Login" status="Up" /> 
      <server name="Training Room" status="Up" /> 
      <server name="Beta Login" status="Up" /> 
      <server name="Beta Server" status="Up" /> 
      </servers>
    I understand that's just the info from the game server and they are all currently "up."

    But I have no idea what to do with the XML feed and how to edit so that it only shows
    <server name="Union" status="Up" />
    <server name="Defiant" status="Up" />
    <server name="Zukunft" status="Up" />
    <server name="Virtue" status="Up" />

    Since these are the main servers my guild plays on, having the rest of the servers will only take up unneeded space on the site.

    How would I go about adding just the info I need from the XML? Someone I talked to said that I'd probably have to add the XML to php, but I have no idea how to go about that. On top of that, I have no idea on how to pull the feed for just the servers I need.

    Yeah, I know... dorky to ask about something for an MMO website. But I've asked everywhere with no responce.

    Hoping someone here can feel my plight and take pity on me and help a poor gamer out

  • #2
    I'm not sure I'm following the whole use of this xml file, but if you just want it to contain the status of your four servers, you can certainly just edit the file and put your servers in it. Then if you want to read it when someone browses the web site, I'd suggest using PHP's SimpleXML interface, which is pretty easy. So at that point if you changed the xml file, your site would show the updated server status without changing your web page.

    Dave

    Comment


    • #3
      Originally posted by tracknut View Post
      I'm not sure I'm following the whole use of this xml file, but if you just want it to contain the status of your four servers, you can certainly just edit the file and put your servers in it. Then if you want to read it when someone browses the web site, I'd suggest using PHP's SimpleXML interface, which is pretty easy. So at that point if you changed the xml file, your site would show the updated server status without changing your web page.

      Dave
      Well, the XML feed is on someone elses website and it pulls the server info from the game servers. The people that created the feed said that others could take the url of the feed and customize the contents so that when it displays on your website it only shows the servers you choose instead of all the servers listed in the feed.

      I talked to someone else I play the game with and said that it can be done and that his old guild was able to modify the feed so that it showed 3 of the servers. But his guild left and he didn't know how to recreate it.

      I know I can download the XML file and edit what I need, just that it's not longer "attached" to the direct feed on the host server. So if I uploaded the XML to my own server, it wouldn't know where to get the live feed from, correct?

      I tried contacting the people that host the feed but it seems that they're no longer around to answer my question about it.

      I'm going to give the SimpleXML interface a whirl and see if it works. How "simple" is it to figure out for a novice?

      Thanks for the reply and hope it works

      Comment


      • #4
        If the xml feed from this other site has the contents you list above, but all the servers are wrong (i.e. not your 4 servers), then what good is it anyway? Yes, it sounds like you've understood me correctly, I just can't see the purpose of maintaining a feed to a different site if all the data in the feed is not correct? Are you trying to append your 4 servers to the "official feed" such that other folks who grab the feed will now see your servers in addition to the 20 or so already in the list? If that's the case, you would need to become the "official feed" yourself.... I don't know if that's what you had in mind.

        But yes, SimpleXML is "simple" and there are a ton of examples online.

        Dave

        Comment


        • #5
          Originally posted by tracknut View Post
          If the xml feed from this other site has the contents you list above, but all the servers are wrong (i.e. not your 4 servers), then what good is it anyway? Yes, it sounds like you've understood me correctly, I just can't see the purpose of maintaining a feed to a different site if all the data in the feed is not correct? Are you trying to append your 4 servers to the "official feed" such that other folks who grab the feed will now see your servers in addition to the 20 or so already in the list? If that's the case, you would need to become the "official feed" yourself.... I don't know if that's what you had in mind.

          But yes, SimpleXML is "simple" and there are a ton of examples online.

          Dave
          The XML feed has my 4 servers in it. So I wouldn't be adding anything to the XML, just removing the unwanted servers that I don't need. Instead of having the 20 servers listed, I'd only be showing 4 of the servers listed.

          Comment


          • #6
            Ah, I get it!

            Yes, then open the file with SimpleXML, and loop through all the servers in the list. When you see yours, print them out; when you see those that aren't yours, ignore them. Should be easy.

            Dave

            Comment


            • #7
              Excellent!

              So, here's my snag with being a novice. I'm reading the SimpleXML manual, and I don't know if it's because my eyes are melting from the 20 hours I've been working on my site, I'm lost.

              Am I supposed to make a php file with the link to the XML inside it, run the php file, then get the info I need?

              Maybe a few hours of sleep will help.

              Comment


              • #8
                Have you used PHP before? Say you want a <div> on your home page with these 4 servers and their status listed. You would take your index.html page, rename it to index.php, and do something like this (completely untested, and obviously partial code) is some relevant place in the file:
                Code:
                <html>
                ...blah blah....
                <div id="server_status">
                <?php
                    $myservers = array ("union","defiant","Zukunft","Virtue");
                
                    $xml = simplexml_load_file('http://example.com/serverstatus.xml');
                    foreach ($xml->servers->server as $s)
                        {
                        if (in_array ($s['name'],$myservers))
                            {
                            echo "<p>".$s['name'].", ".$s['status']."</p>";
                            }
                         }
                ?>
                </div>
                Hope that helps...
                Dave

                Comment


                • #9
                  Ahh, I get you now. Yeah, my experience with php is minimal. Most of the stuff I've done has been based off of php scripts that people have supplied that you can edit to suit your needs. But I think I've got an idea from what you posted and what I'm reading in the simpleXML manual.

                  I'll give this a whirl after some sleep. Thanks again!

                  Comment


                  • #10
                    While tinkering around with this tonight, the creator of the feed got back to me. Looks like he might be giving me the source, so hopefully I can make the feed available to others when his site is down and still get what I need for my site.

                    Thanks again Tracknut!

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎