Hàm xml_set_default_handler() của PHP
❮ Tham chiếu trình phân tích cú pháp XML của PHP
Ví dụ
Tạo trình phân tích cú pháp XML, đặt trình xử lý dữ liệu mặc định và phân tích tài liệu XML ( note.xml ):
<?php
// Create an XML parser
$parser=xml_parser_create();
function def($parser,$data) {
echo $data;
}
// Set the
default data handler
xml_set_default_handler($parser,"def");
$fp=fopen("note.xml","r");
while ($data=fread($fp,4096)) {
// Parse XML data
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s
at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
fclose($fp);
?>
Chạy ví dụ »Định nghĩa và cách sử dụng
Hàm xml_set_default_handler() đặt trình xử lý dữ liệu mặc định cho trình phân tích cú pháp XML.
Hàm này chỉ định hàm nào sẽ được gọi bất cứ khi nào trình phân tích cú pháp tìm thấy dữ liệu trong tệp XML.
Lưu ý: Tham số xử lý cũng có thể là một mảng chứa tham chiếu đối tượng và tên phương thức.
Cú pháp
xml_set_default_handler( parser , handler )
Giá trị tham số
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
handler | Required. Specifies a function to be used as an event handler. The function must have two parameters:
|
Chi tiết kỹ thuật
Giá trị trả về: | ĐÚNG khi thành công. FALSE khi thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu trình phân tích cú pháp XML của PHP