XML_HTMLSax3
[ class tree: XML_HTMLSax3 ] [ index: XML_HTMLSax3 ] [ all elements ]

Source for file SimpleExample.php

Documentation is available at SimpleExample.php

  1. <?php
  2. /***
  3.  * $Id: SimpleExample.php,v 1.3 2004/06/02 14:33:38 hfuecks Exp $
  4.  * Shows all the handlers in use with a simple document
  5.  */
  6. require_once('XML/HTMLSax3.php');
  7.  
  8.  
  9. class MyHandler {
  10.     function MyHandler(){}
  11.     function openHandler($parser,$name,$attrs{
  12.         echo 'Open Tag Handler: '.$name.'<br />' );
  13.         echo 'Attrs:<pre>' );
  14.         print_r($attrs);
  15.         echo '</pre>' );
  16.     }
  17.     function closeHandler($parser,$name{
  18.         echo 'Close Tag Handler: '.$name.'<br />' );
  19.     }
  20.     function dataHandler($parser,$data{
  21.         echo 'Data Handler: '.$data.'<br />' );
  22.     }
  23.     function escapeHandler($parser,$data{
  24.         echo 'Escape Handler: '.$data.'<br />' );
  25.     }
  26.     function piHandler($parser,$target,$data{
  27.         echo 'PI Handler: '.$target.' - '.$data.'<br />' );
  28.     }
  29.     function jaspHandler($parser,$data{
  30.         echo 'Jasp Handler: '.$data.'<br />' );
  31.     }
  32. }
  33.  
  34. $doc=<<<EOD
  35. <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
  36. <html>
  37. <head>
  38. <title>HTML Sax in Action</title>
  39. <meta name="Description" content="Example for HTML Sax">
  40. <!-- Some JavaScript inside a CDATA block coming right up... -->
  41. <script type="application/x-javascript">
  42. <![CDATA[
  43. document.write('<b>Hello World!</b>');
  44. ]]>
  45. </script>
  46. </head>
  47. <body>
  48. <?php
  49. echo ( '<b>This is a processing instruction</b>' );
  50. ?>
  51. <a href="http://www.php.net">PHP</a>
  52. <%
  53. document.write('<i>Hello World!</i>');
  54. %>
  55. </body>
  56. </html>
  57. EOD;
  58.  
  59. // Instantiate the handler
  60. $handler=new MyHandler();
  61.  
  62. // Instantiate the parser
  63. $parser=new XML_HTMLSax3();
  64.  
  65. // Register the handler with the parser
  66. $parser->set_object($handler);
  67.  
  68. // Set a parser option
  69. $parser->set_option('XML_OPTION_TRIM_DATA_NODES');
  70.  
  71. // Set the handlers
  72. $parser->set_element_handler('openHandler','closeHandler');
  73. $parser->set_data_handler('dataHandler');
  74. $parser->set_escape_handler('escapeHandler');
  75. $parser->set_pi_handler('piHandler');
  76. $parser->set_jasp_handler('jaspHandler');
  77.  
  78. // Parse the document
  79. $parser->parse($doc);
  80. ?>

Documentation generated on Mon, 11 Mar 2019 15:11:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.