(Object-O-Meter: fp ^---- oop)

xml_parser_ex1.php
<?php

$xml_file 
'presentations/slides/sdphp/data/sdphp_talk.xml';
$ltag '';
$lcontent '';

// structure for store the document data
$elements = array();

function 
startElement($parser$name$attrs) {
    if (
strtolower($name) == 'talk'// skip the talk element
        
return;
    else
        
$GLOBALS['ltag'] = $name;
}

function 
endElement($parser$name) {
    if (!
trim($GLOBALS['ltag']) == '') {
        
$GLOBALS['elements'][$name] = $GLOBALS['lcontent'];
        
$GLOBALS['ltag'] = $GLOBALS['lcontent'] = '';
    }
}

function 
cData($parser$data) {
    
$GLOBALS['lcontent'] = trim($data);
}

$parser xml_parser_create();
xml_parser_set_option($parserXML_OPTION_CASE_FOLDINGtrue);
xml_set_element_handler($parser'startElement''endElement');
xml_set_character_data_handler($parser'cData');

$fp fopen($xml_file'r');

while (
$data fread($fp1024)) {
    if (!
xml_parse($parser$datafeof($fp))) {
        die(
sprintf("Error in XML file: %s at line %d\n",
                
xml_error_string(xml_get_error_code($parser)),
                
xml_get_current_line_number($parser)));
    }
}

xml_parser_free($parser);
print_r($elements);

?> 
Output
Array
(
    [TITLE] => Mangling XML with PHP
    [DATE] => 2002-08-26
    [SPEAKER] => Jesus M. Castagnetto
    [URL] => http://www.sdphp.net/talks/intro_xml
)