note 36585 deleted from function.xml-set-element-handler by didou
| From: | didou@php.net | Date: | Thu, 03 Feb 2005 20:00:06 +0000 |
| Subject: | note 36585 deleted from function.xml-set-element-handler by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84476@lists.php.net to get a copy of this message | ||
Note Submitter: mutherf0cker at hotmail dot com
----
This article shows a class implementation using xml_set_element_handler() etc: http://www.sitepoint.com/article/560/ (after an
initial non-class implementation). Here's what I've come up with for my own use. Hope
someone finds it useful :)
<?php
class XMLParser
{
// ...
function XMLParser()
{
$this->parser = xml_parser_create();
}
function parse()
{
$this->stack = array(); // this keeps track of what tag level you're at
xml_set_object($this->parser, &$this);
xml_set_element_handler($this->parser, "_startElementHandler",
"_endElementHandler");
// ...
}
function _startElementHandler($parser, $name, $attribs)
{
array_push($this->stack, $name);
return $this->startElementHandler($parser, $name, $attribs);
}
function _startElementHandler($parser, $name, $attribs)
{
// 'virtual' function
// the intention is that subclasses implement startElementHandler() and the
// array_push() in _startElementHandler() still gets run without subclasses having
// to execute it
}
// ...
}
?>