Using a Default Handler : XML Handler « XML « PHP






Using a Default Handler

<?php
     $i = 1;
     function default_handler ($p, $data)
     {
          global $i;
          print ("$i: default: $data\n");
          $i++;
     }
     
     function cdata_handler ($p, $data)
     {
          global $i;
          print ("$i: cdata: $data\n");
          $i++;
     }
     $xml = "<foo>bar</foo><?exec command ?>";
     
     $p = xml_parser_create ();
     xml_set_default_handler ($p, 'default_handler');
     xml_set_character_data_handler ($p, 'cdata_handler');
     
     if (!xml_parse ($p, $xml, true)){
          die (sprintf ("<br />Parse error in <code>%s</code> (%s)",
                        htmlspecialchars ($xml),
                        xml_error_string (xml_get_error_code ($p))));
     }
     xml_parser_free ($p);
?>

           
       








Related examples in the same category

1.XML Cdata handler
2.Parsing a Processing Instruction