Dan,

Thanks for your reply ... Glad to be helpful on the one tidbit I uncovered!

Looks like your conclusion is the same as mine:  the object variables are
readable within the handler functions, but they are not writeable. Hence
your use of the global variables ... That seems to be the only workaround.

I'm convinced this has to be a bug ... Because what good is a "contained"
class if you've got to interact with global variables in order to get the
job done? Theoretically speaking, how do you know that you're not stepping
on the toes of some other global variable?

This solution may be good enough for me and you ... If we're not writing
classes for distribution ... But they go against the grain of all the
bennies I've read about classes.

I'm not normally one to "cry 'BUG!'" ... But I think this qualifies. Do you
agree?

-Clay


> From: Analysis & Solutions <[EMAIL PROTECTED]>
> Date: Wed, 3 Jul 2002 16:38:38 -0400
> To: PHP List <[EMAIL PROTECTED]>
> Subject: Re: [PHP] $this in an XML data handler ... in a class
> 
> Clay:
> 
> On Wed, Jul 03, 2002 at 11:05:34AM -0700, Clay Loveless wrote:
>> 
>> "Note: Instead of a function name, an array containing an object reference
>> and a method name can also be supplied."
> 
> Interesting.  Thanks!
> 
> Anyway, back to your situation.  I put together a test.  Two counters are
> running and get displayed each time each function is called.  One counter
> is a regular variable which I bring into each function via a global
> statement.  The other counter is part of the object.
> 
> Interestingly, in this case, the object variables are not acting as if
> they are part of the class, rather they're behaving as if their scope is
> stuck within each function.
> 
> As far as parsing XML, be aware that the character data handler get's
> called for each bit of non-tag data, including white spaces in tags and
> between tags.  And, character data can contain multiple lines but they get
> passed through the character data handler function one line at a time, not
> all at once.  So, performing maneuvers in the character_handler function
> is tricky.  I save my character data in an array and then implode the
> array in the end handler function.  This process is in the test, below, as
> well.
> 
> I've got a PHP XML expat parsing tutorial up on the web that may prove
> helpful:  http://www.analysisandsolutions.com/code/phpxml.htm
> 
> 
> #! /usr/local/bin/php -q
> <?php
> 
> class Blah
> {
>   var $xmlparser;
>   var $current_element;
>   var $count = 0;
> 
>   function _parseXML($data)
>   {
>       global $g;
>       $g = 0;
> 
>       $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)
>   {
>      global $CData, $g;
>      $CData = array();
>      echo 'g:' . ++$g . ' o:' . ++$this->count . " start\n";
>      echo "  start element: $e_name\n";
>   }
> 
>   function _xml_character_data($p, $data)
>   {
>      global $CData, $g;
>      $CData[] = $data;
>      echo 'g:' . ++$g . ' o:' . ++$this->count . " character\n";
>      echo "  character data: $data\n";
>   }
> 
>   function _xml_end_element($p, $e_name)
>   {
>      global $CData, $g;
>      echo 'g:' . ++$g . ' o:' . ++$this->count . " end\n";
>      echo "  end element: $e_name\n";
>      echo "  end data array: " . trim( implode('', $CData) ) . "\n";
>   }
> 
> 
> } // end of class Blah
> 
> 
> $XML = '
> <doc>
> <item>
> Some Item Text
> </item>
> </doc>
> ';
> 
> echo "$XML\n";
> 
> $Class = new Blah();
> $Class->_parseXML($XML);
> 
> 
> ?>
> 
> 
> Enjoy,
> 
> --Dan
> 
> -- 
>              PHP classes that make web design easier
>       SQL Solution  |   Layout Solution   |  Form Solution
>   sqlsolution.info  | layoutsolution.info |  formsolution.info
> T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
> 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to