Kastang Ramblings of a Geek

7Jan/111

Parsing the WoW Armory without XML – Part 2

This post is a continuation of my original post about parsing the WoW Armory with no XML feeds available. In my original post, I showed how to pull basic character information, such as professions and talents, from each member in a specified guild. This post will expand on more specific character information such as HP, MP, and Stats.

The getCharacterInformation($charName) function in my previous post can be expanded to include additional information available on the WoW Armory. (Please view my original post for the sample code). For the most part, the code below can be directly copied into the existing method. As in my previous post, I assume you have the knowledge to make minor changes to the method (such as modifying the return array).

Exact Health and Mana:

$health = $xpath->query('//li[@class="health"]/span[@class="value"]');
$mana = $xpath->query('//li[@id="summary-power"]/span[@class="value"]');
echo $health->item(0)->nodeValue."<br />";
echo $mana->item(0)->nodeValue."<br />";

Exact Talents:
This will return the exact talent in the form of xx/xx/xx for both talents.

$exactBuilds = $xpath->query('//span[@class="name-build"]/span[@class="build"]');
echo $exactBuilds->item(0)->nodeValue."<br />";
echo $exactBuilds->item(1)->nodeValue;

Stats and Resistances:
A stat listed in the comment above the code needs to be added to the $stat variable.

/**
 * Valid $stat values:
 * strength, agility, stamina, intellect,
 * spirit, mastery, meleedamage, meleedps,
 * meleeattackpower, meleespeed, meleehaste,
 * meleehit, meleecrit, meleecrip, expertise,
 * rangeddamage, rangeddps, rangedattackpower,
 * rangedspeed, rangedhaste, rangedhit, rangedcrit,
 * spellpower, spellhaste, spellhit, spellcrit,
 * spellpenetration, manaregen, combatregen, armor,
 * dodge, parry, block, resilience, arcaneres, fireres,
 * frostres, natureres, shadowres,
 */
 
$stat = "ADD_STAT_FROM_ABOVE_HERE";
$statName = $xpath->query('//li[@data-id="'.$stat.'"]/span[@class="name"]');
$statValue = $xpath->query('//li[@data-id="'.$stat.'"]/span[@class="value"]');
echo $statName->item(0)->nodeValue."<br />";
echo $statValue->item(0)->nodeValue."<br />";

Battleground Rating and Kills

$rating = $xpath->query('//li[@class="rating"]/span[@class="value"]');
$kills = $xpath->query('//li[@class="kills"]/span[@class="value"]');
echo $rating->item(0)->nodeValue."<br />";
echo $kills->item(0)->nodeValue."<br />";

My next post will cover looking into more interesting character information such as Achievements, Reputation, or Statistics.

12Jan/100

Parsing the WoW Armory – Part 2.1

I forgot to post this information in Part 2 of Parsing the WoW Armory. When parsing the guild-info.xml file, some fields are represented by  numerical values. Below is conversion table from XML numerical representations to actual values.

genderId:
0 - Male
1 - Female

raceId:
1 - Human
2 - Orc
3 - Dwarf
4 - Night Elf
5 - Undead
6 - Tauren
7 - Gnome
8 - Troll
10 - Blood Elf
11 - Draenei

classId:
1 - Warrior
2 - Paladin
3 - Hunter
4 - Rogue
5 - Priest
6 - Death Knight
7 - Shaman
8 - Mage
9 - Warlock
11 - Druid

For easy converting from numerical to actual values I would recommend using a PHP array(). Below is an example of the Sorted Guild list from Part 2 with the addition of the class of each character included.

< ?php
function sortedList($x) {
    $classArray = array(1 => "Warrior", 2 => "Paladin", 3 => "Hunter", 4 => "Rogue", 5 => 
          "Priest", 6 => "Death Knight", 7 => "Shaman", 8 => "Mage", 9 => "Warlock", 11 => "Druid");
 
    $array = array();
    foreach($x as $char) {
        $array[] = getName($char)." - ".getLevel($char)." - ".$classArray[(int)getClassId($char)]."<br />";
    }
    sort($array);
 
    return $array;
}
 
?>
12Jan/100

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);
 
?>