class XMLParser
{
/**
* @var string
* @access protected
*/
var $current = '';
/**
* @var boolean
* @access protected
*/
var $found = false;
/**
* @var array
* @access protected
*/
var $result = array();
/**
* @access public
*/
function XMLParser()
{
$this->__construct();
}
/**
* @access public
*/
function __construct()
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'startElement', 'endElement');
xml_set_character_data_handler($this->parser, 'characterData');
}
/**
* @param string $xml_data
* @access public
*/
function parse($xml_data)
{
xml_parse($this->parser, $xml_data);
xml_parser_free($this->parser);
return $this->result;
}
/**
* @param object $parser
* @param string $name
* @param array $attribs
* @access protected
*/
function startElement($parser, $name, $attribs)
{
$this->current = $name;
if ($this->current == 'ENTRY')
{
$this->found = true;
$this->result[count($this->result)] = array();
}
elseif ($this->found and $this->current == 'LINK')
{
$this->result[count($this->result) - 1][$attribs['REL']] = $attribs['HREF'];
}
}
/**
* @param object $parser
* @param string $name
* @access protected
*/
function endElement($parser, $name)
{
if ($name == 'ENTRY')
{
$this->found = false;
}
}
/**
* @param object $parser
* @param string $data
* @access protected
*/
function characterData($parser, $data)
{
if ($this->found)
{
$this->result[count($this->result) - 1][strtolower($this->current)] = $data;
}
}
}