PHP 7 xml_set_default_handler() Function
Example
Create an XML parser, set default data handler, and parse an XML document (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);
?>
Run Example »
Definition and Usage
The xml_set_default_handler() function sets the default data handler for the XML parser.
This function specifies what function to be called whenever the parser finds data in the XML file.
Note: The handler parameter can also be an array containing an object reference and a method name.
Syntax
xml_set_default_handler(parser, handler)
| 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:     
  | 
  
Technical Details
| Return Value: | TRUE on success. FALSE on failure | 
|---|---|
| PHP Version: | 4.0+ | 
❮ PHP XML Parser Reference

