Current Location: Home> Function Categories> xml_set_default_handler

xml_set_default_handler

Set the default handler
Name:xml_set_default_handler
Category:XML parser
Programming Language:php
One-line Description:Sets the default data handler for the XML parser.

Definition and usage

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.

Example

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

grammar

 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:

  • $parser - Variable containing the XML parser that calls the handler
  • $data - A string variable containing character data from an XML file
Similar Functions
Popular Articles