XML parsing question

Hi,

I currently have this XML…

<?xml version="1.0"?>
<cal>
  <dates1><date>105909</date><event>Summer Holiday</event></dates1>
  <dates1><date>106909</date><event>School Trip Somewhere</event></dates1>
  <dates1><date>107909</date><event>Summer Holiday</event></dates1>
  <dates1><date>108909</date><event>School Trip Somewhere</event></dates1>
  <dates1><date>109909</date><event>Summer Holiday</event></dates1>
  <dates1><date>1010909</date><event>School Trip Somewhere</event></dates1>
  <dates1><date>1014909</date><event>Summer Holiday</event></dates1>
  <dates1><date>1027909</date><event>School Trip Somewhere</event></dates1>
 
  <dates2><date>2010909</date><event>Summer Holiday</event></dates2>
  <dates2><date>2011909</date><event>School Trip Somewhere</event></dates2>
  <dates2><date>2012909</date><event>Summer Holiday</event></dates2>
  <dates2><date>2013909</date><event>School Trip Somewhere</event></dates2>
</cal>

And i can successfully parsed the ‘dates1’ data in PHP using the code below, which is based on the kirupa intermediate xml parsing tutorial…

 
<?php
$xml_file = "dates.xml"; 
$xmldateKey = "*CAL*DATES1*DATE"; 
$xmleventKey = "*CAL*DATES1*EVENT"; 
$dates1 = array(); 
$counter = 0; 
class xml_story{ var $xmldate, $xmlevent; } 
function startTag($parser, $data){ global $current_tag; $current_tag .= "*$data"; } 
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, $xmldateKey, $xmleventKey, $counter, $dates1; 
    switch($current_tag){ 
        case $xmldateKey: 
            $dates1[$counter] = new xml_story(); 
            $dates1[$counter]->xmldate = $data; 
            break; 
        case $xmleventKey: 
            $dates1[$counter]->xmlevent = $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($xml_file, "r") or die("Could not open file"); 
$data = fread($fp, filesize($xml_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)); 
} 
xml_parser_free($xml_parser); 
fclose($fp); 
$day3 = array(3010909, 3020909);
$day4 = array(4010909, 4014909, 4027909);
?>

However, the only way i can parse the ‘dates2’ data is by basically duplicating all the above code and have all new variables, even though i know there must be a better way of doing it.

So, my question is how can i edit the above code to also put all the data from the ‘dates2’ part of the xml into an array called ‘dates2’?

Any help would be greatly appreciated