xml_set_default_handler
Set the default handler
The xml_set_default_handler()
function is used to set the default data handler for the XML parser.
This function specifies the function to be called when the parser finds data in the XML file.
Note: The handler parameter can also be an array containing object references and method names.
Create an XML parser, set the default data handler, and parse the XML document ( note.xml ):
<?php // Create XML parser $parser = xml_parser_create ( ) ; function def ( $parser , $data ) { echo $data ; } // Set the default data processor 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 on line %d" , xml_error_string ( xml_get_error_code ( $parser ) ) , xml_get_current_line_number ( $parser ) ) ) ; } xml_parser_free ( $parser ) ; fclose ( $fp ) ; ?>
Run the instance
xml_set_default_handler ( parser , handler )
parameter | describe |
---|---|
parser | Required. Specify the XML parser to use |
Handler |
Required. Specifies the function used as the event handler. The function must have two parameters:
|