XML Parser, MultiLevel Nodes & Jubba's Tutorial

I found the wonderful tutorial Jubba wrote and this forum through it - and was able to get my parser up & running really quickly, although not fully. For about 3 days I’ve been working at it, and I am still unable to parse multilevel nodes that only sometimes exist.

Code is below. The issue is when I get to the ‘tradeskills’ area, as not each ‘character’ will have it. If I uncomment the skills - it returns the 3 folks with any one of those skills, and the very last guy. Commented, it returns all 77 characters as it should.

Realm also does not seem to work, though I can get it to echo out, missing something to get it into the array apparently - though not worried about that so much as it not providing this sometimes - existent nodes’ information.

Any pointers would be greatly appreciated!
-Ser


<?php

$file = "3632.xml";
// http://guilds.camelotherald.com/guilds/Galahad/3632.xml

// Tag Keys
$realm_key = "*GUILD*REALM";
$characterName_key = "*GUILD*CHARACTERS*CHARACTER";
$id_key = "*GUILD*CHARACTERS*CHARACTER*ID";
$server_key = "*GUILD*CHARACTERS*CHARACTER*SERVER";
$race_key = "*GUILD*CHARACTERS*CHARACTER*RACE";
$class_key = "*GUILD*CHARACTERS*CHARACTER*CLASS";
$level_key = "*GUILD*CHARACTERS*CHARACTER*LEVEL";
$mlevel_key = "*GUILD*CHARACTERS*CHARACTER*MLEVEL";
$mpath_key = "*GUILD*CHARACTERS*CHARACTER*MPATH";
$totalrp_key = "*GUILD*CHARACTERS*CHARACTER*TOTALRP";
$lastweekrp_key = "*GUILD*CHARACTERS*CHARACTER*LASTWEEKRP";
$alchemy_key = "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*ALCHEMY";
$armorcraft_key = "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*ARMORCRAFT";
$fletching_key= "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*FLETCHING";
$spellcraft_key = "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*SPELLCRAFT";
$tailoring_key = "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*TAILORING";
$weaponcraft_key = "*GUILD*CHARACTERS*CHARACTER*TRADESKILLS*WEAPONCRAFT";


// Initialize
$toon_array = array();
$counter = "0";

class xml_toon
    {var $characterName, $LastOn, $id, $realm, $server, $race, $class, $level, $mlevel, $mpath, $totalrp, $lastweekrp, $alchemy, $armorcraft, $fletching, $spellcraft, $tailoring, $weaponcraft;}

function startTag($parser, $data, $attr)
    {global $current_tag;
    global $ToonName;
    global $LastOn;
    $current_tag .= "*$data";
    
    if (is_array($attr))
        {while(list($key,$val) = each($attr))
            {if ($key == "NAME")
                {$ToonName = $val;}
            if ($key == "LASTON")
                {$LastOn = $val;}}
        }
    }

function endTag($parser, $data)
    {global $current_tag;
    $tag_key = strrpos($current_tag, '*');
    $current_tag = substr($current_tag, 0, $tag_key);}

function contents($parser, $data)
    {global $current_tag, $ToonName, $LastOn, $id_key, $realm_key, $server_key, $race_key, $class_key, $level_key, $mlevel_key, $mpath_key, $totalrp_key, $lastweekrp_key, $alchemy_key, $armorcraft_key, $fletching_key, $spellcraft_key, $tailoring_key, $weaponcraft_key, $counter, $toon_array;
    
    switch($current_tag)
        {case $id_key:
        $toon_array[$counter] = new xml_toon();
        $toon_array[$counter]->characterName = $ToonName;
        $toon_array[$counter]->LastOn = $LastOn;
        $toon_array[$counter]->id = $data;
        break;
        
        case $realm_key:
        echo "<br>Realm:  ";
        echo $data;
        $toon_array[$counter]->realm = $data;
        break;
        
        case $server_key:
        $toon_array[$counter]->server = $data;
        break;
        
        case $race_key:
        $toon_array[$counter]->race = $data;
        break;
        
        case $class_key:
        $toon_array[$counter]->class = $data;
        break;

        case $level_key:
        $toon_array[$counter]->level = $data;
        break;

        case $mlevel_key:
        $toon_array[$counter]->mlevel = $data;
        break;

        case $mpath_key:
        $toon_array[$counter]->mpath = $data;
        break;

        case $totalrp_key:
        $toon_array[$counter]->totalrp = $data;
        break;
        
        case $lastweekrp_key:
        $toon_array[$counter]->lastweekrp = $data;
//        break;
//
//        case $alchemy_key:
//        $toon_array[$counter]->alchemy = $data;
//        break;
//
//        case $armorcraft_key:
//        $toon_array[$counter]->armorcraft = $data;
//        break;
//
//        case $fletching_key:
//        $toon_array[$counter]->fletching = $data;
//        break;
//
//        case $spellcraft_key:
//        $toon_array[$counter]->spellcraft = $data;
//        break;
//        
//        case $tailoring_key:
//        $toon_array[$counter]->tailoring = $data;
//        break;
//        
//        case $weaponcraft_key:
//        $toon_array[$counter]->weaponcraft = $data;
        $counter++;
        break;
        }
    
    }

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startTag", "endTag");

xml_set_character_data_handler($xml_parser, "contents");

$fp = fopen($file, "r") or die("Could not open file");

$data = fread($fp, filesize($file)) or die("Could not read file");

if(!(xml_parse($xml_parser, $data, feof($fp))))
    {die("Error on line " . xml_get_current_line_number($xml_parser));}

fclose($fp);

xml_parser_free($xml_parser);

// Page here!

echo "<pre>";
echo print_r($toon_array);
echo "</pre>";

?>