xml_set_object
使 XML 解析器用類。
語法: void xml_set_object(int parser, object &object);
返回值: 無
函數種類: 資料處理
本函數讓解析器能使用類的方式,值得注意的是這個函數在 PHP 4.0 以上的版本纔可使用。參數 parser 為 xml_parser_create() 所返回的解析代碼。參數 &object 是類本身的指針。
<?php class xml { var $parser;
function xml() { $this->parser = xml_parser_create(); xml_set_object($this->parser,&$this); xml_set_element_handler($this->parser,"tag_open","tag_close"); xml_set_character_data_handler($this->parser,"cdata"); }
function parse($data) { xml_parse($this->parser,$data); }
function tag_open($parser,$tag,$attributes) { var_dump($parser,$tag,$attributes); }
function cdata($parser,$cdata) { var_dump($parser,$cdata); }
function tag_close($parser,$tag) { var_dump($parser,$tag); }
} // end of class xml
$xml_parser = new xml(); $xml_parser->parse("<A ID=\"hallo\">PHP</A>"); ?>
整理: 夕垌菪姬 (天地JPLOP)
|