note 36585 added to function.xml-set-element-handler

From: Date: Wed, 15 Oct 2003 15:21:57 +0000
Subject: note 36585 added to function.xml-set-element-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-58636@lists.php.net to get a copy of this message
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 :) 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 } // ... } ---- Manual Page -- http://www.php.net/manual/en/function.xml-set-element-handler.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36585 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36585&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36585&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58636) next »