void xml_set_object
(int parser, object &object);This function makes parser useable from within object. All callback functions settet via xml_set_element_handler() etc are assumed to be methods of object.
1 2 <?php 3 class xml { 4 var $parser; 5 6 function xml() { 7 $this->parser = xml_parser_create(); 8 xml_set_object($this->parser,&$this); 9 xml_set_element_handler($this->parser,"tag_open","tag_close"); 10 xml_set_character_data_handler($this->parser,"cdata"); 11 } 12 13 function parse($data) { 14 xml_parse($this->parser,$data); 15 } 16 17 function tag_open($parser,$tag,$attributes) { 18 var_dump($parser,$tag,$attributes); 19 } 20 21 function cdata($parser,$cdata) { 22 var_dump($parser,$cdata); 23 } 24 25 function tag_close($parser,$tag) { 26 var_dump($parser,$tag); 27 } 28 29 } // end of class xml 30 31 $xml_parser = new xml(); 32 $xml_parser->parse("<A ID=\"hallo\">PHP</A>"); 33 ?> 34 |
Note: xml_set_object() handling was added in PHP 4.0.