note 36585 modified in function.xml-set-element-handler by aidan

From: Date: Thu, 17 Jun 2004 12:49:18 +0000
Subject: note 36585 modified in function.xml-set-element-handler by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71225@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 :) <?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 } // ... } ?> --was-- 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 } // ... } http://php.net/manual/en/function.xml-set-element-handler.php

« previous php.notes (#71225) next »