PHP xml_set_character_data_handler() Function
In this chapter you will learn:
- Description for PHP xml_set_character_data_handler() Function
- Syntax for PHP xml_set_character_data_handler() Function
- Parameter for PHP xml_set_character_data_handler() Function
- Notes for PHP xml_set_character_data_handler() Function
- Return for PHP xml_set_character_data_handler() Function
- Example - Set the character data handler for the XML parser
Description
The xml_set_character_data_handler() function sets the character data handler for the XML parser.
This function specifies what function to be called when the parser finds character data in the XML file.
Syntax
PHP xml_set_character_data_handler() Function has the following syntax.
xml_set_character_data_handler(parser,handler)
Parameter
Parameter | is Required | Description |
---|---|---|
parser | Required. | XML parser to use |
handler | Required. | A function to be used as an event handler |
The Function specified by the "handler" parameter must have two parameters:
Parameter | Is Required | Description |
---|---|---|
parser | Required. | A variable containing the XML parser calling the handler |
data | Required. | A variable containing the character data from the XML file as a string |
Notes
The handler parameter can also be an array containing an object reference and a method name.
Return
This function returns TRUE on success, or FALSE on failure.
Example
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>//ja v a 2 s . c o m
<name>PHP</name>
<name>Java</name>
</books>
PHP Code
<?php/*ja v a 2 s.com*/
$parser=xml_parser_create();
function char($parser,$data){
echo $data;
}
xml_set_character_data_handler($parser,"char");
$fp=fopen("test.xml","r");
while ($data=fread($fp,1024)){
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);
?>
Next chapter...
What you will learn in the next chapter:
- Description for PHP xml_set_default_handler() Function
- Syntax for PHP xml_set_default_handler() Function
- Parameter for PHP xml_set_default_handler() Function
- Return for PHP xml_set_default_handler() Function
- Example - Set the default data handler for the XML parser
Home » PHP Tutorial » PHP XML Functions