You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 49 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - parse XML file for server stats [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
X-Faith
Nuke Soldier
Nuke Soldier


Joined: Jul 26, 2003
Posts: 27

Location: San Diego

PostPosted: Tue Aug 12, 2003 10:12 pm Reply with quoteBack to top

Well i have the XML (server stats from AC2HQ) doc but i can only figure out how to get stuff from the first area.

Code:
- <ac2hqstats version="0.2" timestamp="2003-08-11 4:37:39 PDT">
  <totals count="13" population="788" />
- <server name="Coldeve" id="1" datacenter="US">
  <population current="65" limit="1800" />
  </server>
- <server name="Darktide" id="2" datacenter="US">
  <population current="33" limit="1800" />
  </server>
- <server name="Frostfell" id="3" datacenter="US">
  <population current="142" limit="1800" />
  </server>
- <server name="Harvestgain" id="4" datacenter="US">
  <population current="49" limit="1800" />
  </server>
- <server name="Leafcull" id="5" datacenter="US">
  <population current="55" limit="1800" />
  </server>
- <server name="Morningthaw" id="6" datacenter="US">
  <population current="42" limit="1800" />
  </server>
- <server name="Snowreap" id="7" datacenter="US">
  <population current="0" limit="1800" />
  </server>
- <server name="Solclaim" id="8" datacenter="US">
  <population current="52" limit="1800" />
  </server>
- <server name="ThistleDown" id="9" datacenter="US">
  <population current="47" limit="1800" />
  </server>
- <server name="Wintersebb" id="10" datacenter="US">
  <population current="34" limit="1800" />
  </server>
- <server name="Dawnsong" id="11" datacenter="EU">
  <population current="121" limit="2000" />
  </server>
- <server name="Abendgrau" id="12" datacenter="EU">
  <population current="55" limit="2000" />
  </server>
- <server name="Seleilcouche" id="13" datacenter="EU">
  <population current="93" limit="2000" />
  </server>
  </ac2hqstats>



Here is the code that i am sorta using Smile once again borrowing/editing. ANd hopefully learning.~!
Code:

$insideitem = false;
$tag = "";
$ac2_server = "";
$ac2_datac = "";
$ac2_population = "";
$ac2_limit ="";
$ac2_totalpop=0;

function startElement($parser, $tagName, $attrs) {   
global $insideitem, $tag, $ac2_server, $ac2_datac, $ac2_population;
   if ($insideitem) {
      $tag = $tagName;
   } elseif ($tagName == "SERVER")
   {

   $insideitem = true;   
   while (list ($key, $val) = each ($attrs)) {
      switch($key) {
      case "NAME": $ac2_server=$val;break;
      case "DATACENTER" : $ac2_datac=$val;break;
      } // end case
   } // end while
   }

}


function characterData($parser, $data) {   
global $insideitem, $tag, $ac2_server, $ac2_population, $ac2_limit, $ac2_totalpop;
   if ($insideitem) {
     switch ($tag) {           
      case "CURRENT":   $ac2_population .= $data;
               $ac2_totalpop += $data; break;   
      case "LIMIT":   $ac2_limit .= $data; break;
      }   
   }

}


function endElement($parser, $tagName) {   
global $insideitem, $tag, $ac2_server, $ac2_datac, $ac2_population, $ac2_limit;
   if ($tagName == "SERVER") {
      print "<TR><TD><b>$ac2_server</b>";
      print "<TD>$ac2_datac</td>";
      print "</TD>";
      print "<TD>$ac2_population</TD>";
      print "<TD>$ac2_limit</TD></TR>\n";

      $ac2_server = "";
      $ac2_datac = "";       
      $ac2_population = "";       
      $ac2_limit = "";
      $insideitem = false;   
   }
}


// gotta have this for the php-NUKE block stuff to work
global $ac2_totalpop;

// Create an XML parser
$xml_parser = xml_parser_create();

// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, "startElement", "endElement");

// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, "characterData");


// print "<hr>\n";
print "<TABLE BORDER=0 WIDTH=0%>\n<TR>\n";
print  "<TD><B>Server</B></TD><TD><B>Location</B></TD><TD><B>Users</B></TD><TD><B>Limit</B></TD>\n";
print "</TR>\n";

// Open the XML file for reading
$fp = fopen("http://localhost/xmlstat.xml","r")  or die("Error reading RSS data.");

// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))   
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
      or die(sprintf("XML error: %s at line %d",
         xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);

print "<TR><TD>Total Users</TD><TD></TD><TD>$ac2_totalpop</TD></TR>\n";
print "</TABLE>\n";


// Free up memory used by the XML parser
xml_parser_free($xml_parser);



// end of file

?>


Well hopefully someone can help thx

X
[/code]
Find all posts by X-FaithView user's profileSend private messageSend e-mailAIM AddressYahoo MessengerMSN Messenger
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.160 Seconds - 190 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::