• PHP Video Tutorials

PHP - Function XML Set Default Handler



Syntax

xml_set_default_handler(parser,handler)

Definition and Usage

It used to set up default handler

Return Values

It returns True on success or false on failure

Parameters

Sr.No Parameters & Description
1

parser

A reference to the XML parser to free.

2

handler

It is used to specifies a function to be used as an event handler

Example

Try out the following example

<?xml version = "1.0" encoding = "UTF-8"?>

<note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>

PHP code is as follows

<?php
   $input = xml_parser_create();
   
   function default($input,$data){
      echo $data;
   }
   
   xml_set_default_handler($input,"default");
   $fp = fopen("sample.xml","w");
   
   while ($data=fread($fp,4096)) {
      xml_parse($input,$data,feof($fp)) or 
      die (sprintf("XML Error: %s at line %d", 
      
      xml_error_string(xml_get_error_code($input)),
      xml_get_current_line_number($input)));
   }
   xml_parser_free($input);
?>

This will produce following result −

Tove Jani Reminder Don't forget me this weekend!
php_function_reference.htm
Advertisements