PHP完全中文操作手冊

天地JPLOP | PHP首頁 | 函數索引
函數:xml_set_object()

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)

[ 上一頁 回主目錄 下一頁 ]
版權所有,天地JPLOP、爵堤亞(夕垌菪姬)。網頁背景音樂和各鍊結標題
及鍊結內容和文章小說,版面編排皆歸原權利人所有對本版面
有任何意見或指教,歡迎至論壇指教。