"Clay Loveless" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Here's a brain-bender ... At least it is for me at the moment. : ) > > When I use an XML parser inside a class, the xml_*_handler functions aren't > recognizing "$this->" variables. I can kind of see why ... But would like it > to work anyway. : ) > > Here's an example: > > class Blah > { > var $xmlparser; > var $current_element; > > // ... > > function _parseXML($data) > { > $this->xmlparser = xml_parser_create(); > xml_set_element_handler( > $this->xmlparser, > array($this,"_xml_start_element"), > array($this,"_xml_end_element")); > xml_set_character_data_handler( > $this->xmlparser, > array($this,"_xml_character_data")); > xml_parse($this->xmlparser, $data); > xml_parser_free($this->xmlparser); > } > > function _xml_start_element($p, $e_name, $e_attributes) > { > $this->current_element = $e_name; > } > > function _xml_end_element($p, $e_name) > { > // ... > } > > function _xml_character_data($p, $data) > { > echo "element is: ".$this->current_element."\n"; > echo "data is: $data\n"; > } > > } // end of class Blah > > > > When this XML parser gets called from within the Blah class, the "element > is:" portion of _xml_character_data comes out blank! > > This sort of makes sense, because the callback functions are "children" of > the xml_parser_create "parent" ... But should that make the children > ignorant of the "grandparent" variables referred to by $this->varname? > > I hope this makes sense ... Has anyone else encountered this sort of > problem? I'm an old hat at PHP, but am relatively new to both XML parsing > and writing my own classes. > > Thanks, > Clay >
Have a look at: http://www.php.net/manual/en/function.xml-set-object.php xml_set_object($this->parser, &$this); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php