xml_set_character_data_handler
Setting up character data processor
xml_set_character_data_handler()
function is used to set up a character data handler for the XML parser.
This function specifies the function to be called when the parser finds character 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 up a character data handler, and parse the XML document ( note.xml ):
<?php // Create XML parser $parser = xml_parser_create ( ) ; function char ( $parser , $data ) { echo $data ; } // Set character data processing program xml_set_character_data_handler ( $parser , "char" ) ; $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_character_data_handler ( parser , handler )
parameter | describe |
---|---|
parser | Required. Specifies the XML parser to use. |
Handler |
Required. Specifies the function used as the event handler. The function must have two parameters:
|