Parsing the WoW Armory – Part 2
I chose to expand on Part 1 by providing a function file that provides access to all available character related information from the guild-info.xml file from the WoW Armory. The guild-info.xml file provides the following information for the entire guild: Achievement Points, Class ID, Gender ID, Level, Character Name, Race ID, Guild Rank, URL to Character Page.
Some neat things can be calculated by using the available resources. I provided three examples in the code below: Average achievement points, average level, and a sorted list of all characters in the guild (also provided in Part 1).
< ?php ini_set("user_agent", "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"); //Average guild achievement score. function achAverage($x) { $counter = 0; $total = 0; foreach ($x as $p) { $total += getAchPoints($p); $counter++; } return ($total/$counter); } //Sorted Guild Characters Names/Levels in ABC Order. function sortedList($x) { $array = array(); foreach($x as $char) { $array[] = getName($char)." - ".getLevel($char)."<br>"; } sort($array); return $array; } //Returns the average level of the entire guild. function avgLevel($x) { $counter = 0; $total = 0; foreach ($x as $p) { $total += getLevel($p); $counter++; } return ($total/$counter); } /** * Other functions that can be used to pull information * from the XML sheet. Use these functions to expand * and create other functions. **/ function getAchPoints($x) { return $x['achPoints']; } function getClassId($x) { return $x['classId']; } function getGenderId($x) { return $x['genderId']; } function getLevel($x) { return $x['level']; } function getName($x) { return $x['name']; } function getRaceId($x) { return $x['raceId']; } function getRank($x) { return $x['rank']; } function getURL($x) { return $x['url']; } ?>
New functions can be created by using the get functions at the bottom of the file. Using the get functions and sample functions, it should be easy enough to expand on what I have.
The below code is an example of how to use the function code from above.
< ?php //Functions file. include ('guild.php'); //Set Server/Guild Here. $server = "Eitrigg"; $guild = "We+Know"; $url='http://www.wowarmory.com/guild-info.xml?r='.$server.'&gn='.$guild; $xml = simplexml_load_file($url); $xml = $xml->guildInfo->guild->members->character; //-------ABOVE THIS LINE IS REQUIRED---------- //Below are some possible ways to use the functions. /** Prints Without Array Numbers **/ for($i=0, $array = sortedList($xml);$array[$i] != null; $i++) { echo $array[$i]; } /** Alternative Implementation, Prints with Array Numbers print_r(sortedList($xml)); **/ //Displays the average number of guild achievements. echo achAverage($xml)."<br />"; //Displays the average level of the guild. echo avgLevel($xml); ?>

ScifiToday