Re: xml_set_character_data_handler logic

From: Date: Mon, 30 Sep 2002 18:36:58 +0000
Subject: Re: xml_set_character_data_handler logic
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-118246@lists.php.net to get a copy of this message
Cardinal from IRC answered my question. It turns out that when you indent your childs with tabs, it sees those tabs as cdata of the root element. I had the following XML file: <settings> <dbname>sampleDBName</dbname> <dbuser>sampleUser</dbuser> <dbhost>localhost</dbhost> </settings> The tabs in front of the child elements were treated as CDATA of the <settings> root node. "Leendert" <goat@daholygoat.com> wrote in message news:20020930103413.49695.qmail@pb1.pair.com... > "Leendert" <goat@daholygoat.com> wrote in message > news:20020930102719.45073.qmail@pb1.pair.com... > > It appears that: > > > > xml_set_character_data_handler($parser, 'handleData'); > > > > calls handleData() 3 times per element. Does anyone know the reason behind > > this? Sounds like that could be very inefficient. > > > > > > FYI, this is the code I'm using: > > <?php > class XMLSettingsParser > { > var $settingsFile; > var $xmlData; > var $parser; > var $tempElementName; > > function XMLSettingsParser($settingsFile) > { > $this->SettingsFile = $settingsFile; > > $this->xmlData = implode('', file($settingsFile)); > > $this->parser = xml_parser_create(); > xml_set_object($this->parser, &$this); > > xml_set_element_handler($this->parser, 'handleStartElement', > 'handleEndElement'); > xml_set_character_data_handler($this->parser, 'handleData'); > > xml_parse($this->parser, $this->xmlData); > xml_parser_free($this->parser); > } > > function handleStartElement($parser, $name, $attribs) > { > $this->tempElementName = $name; > } > > function handleEndElement() > {} > > function handleData($parser, $data) > { > //if(!defined($this->tempElementName)) > define($this->tempElementName, $data); > } > } > ?> > > It gives me 2 notices per element that the constant is already defined, > while it shouldn't. When I do use the conditional > if(!defined($this->tempElementName)) it works fine of course. But it should > work in the first place. > Note: you need error_reporting(E_NOTICE); on to see the error. > > > >

« previous php.general (#118246) next »