English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The xml_set_default_handler() function is used to establish the default data handler for the XML parser.
xml_set_default_handler(parser,handler)
Establishes the default handler function for the XML parser specified by parser.
Returns True on success, false on failure
Number | Parameters and Description |
---|---|
1 | parser XML parser reference used to establish the default handler function. |
2 | handler It is used to specify the function used as the event handler |
Try the following example, file name: sample.xml
<?xml version = "1.0" encoding = "UTF-8"?> <note> <to>Tove</to>/to> <from>Jani</from>/from> <heading>Reminder</heading>/heading> Don't forget me this weekend! </note>
The following PHP code is given below
<?php $input = xml_parser_create(); function default($input,$data){ echo $data; } xml_set_default_handler($input,"default"); $fp = fopen("sample.xml","w"); while ($data=fread($fp,4096)) { xml_parse($input,$data,feof($fp)) || die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($input)), xml_get_current_line_number($input))); } xml_parser_free($input); ?>
Output Result
Tove Jani Reminder Don't forget me this weekend!