In a follow up on this, here's something else that's kind of bizzare ...
Within this class example, if I add a variable declaration of:
var $testval = 'this is a test';
And then add to _xml_character_data():
echo "TEST: $this->testval\n";
... I find that within the class structure, _xml_character_data can READ the
$this->testval values (set outside of any callback function), but apparently
the _xml_start_element() callback function cannot SET
$this->current_element.
My output is:
element is:
data is: [valid data]
TEST: this is a test
Is this a bug? It's beginning to have the feel of one...
-Clay
>>> 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
>>>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php