home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _dd5462947fb9d4e35508f7595e6e5a70 < prev    next >
Text File  |  2000-03-23  |  8KB  |  178 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>HTML::Parser - SGML parser class</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> HTML::Parser - SGML parser class</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#efficiency">EFFICIENCY</A></LI>
  26.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  27.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  28. </UL>
  29. <!-- INDEX END -->
  30.  
  31. <HR>
  32. <P>
  33. <H1><A NAME="name">NAME</A></H1>
  34. <P>HTML::Parser - SGML parser class</P>
  35. <P>
  36. <HR>
  37. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  38. <UL>
  39. <LI>Linux</LI>
  40. <LI>Solaris</LI>
  41. <LI>Windows</LI>
  42. </UL>
  43. <HR>
  44. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  45. <PRE>
  46.  require HTML::Parser;
  47.  $p = HTML::Parser->new;  # should really a be subclass
  48.  $p->parse($chunk1);
  49.  $p->parse($chunk2);
  50.  #...
  51.  $p->eof;                 # signal end of document</PRE>
  52. <PRE>
  53.  # Parse directly from file
  54.  $p->parse_file("foo.html");
  55.  # or
  56.  open(F, "foo.html") || die;
  57.  $p->parse_file(\*F);</PRE>
  58. <P>
  59. <HR>
  60. <H1><A NAME="description">DESCRIPTION</A></H1>
  61. <P>The <CODE>HTML::Parser</CODE> will tokenize an HTML document when the <A HREF="#item_parse"><CODE>parse()</CODE></A>
  62. method is called by invoking various callback methods.  The document to
  63. be parsed can be supplied in arbitrary chunks.</P>
  64. <P>The external interface the an <EM>HTML::Parser</EM> is:</P>
  65. <DL>
  66. <DT><STRONG><A NAME="item_new">$p = HTML::Parser->new</A></STRONG><BR>
  67. <DD>
  68. The object constructor takes no arguments.
  69. <P></P>
  70. <DT><STRONG><A NAME="item_parse">$p->parse( $string );</A></STRONG><BR>
  71. <DD>
  72. Parse the $string as an HTML document.  Can be called multiple times.
  73. The return value is a reference to the parser object.
  74. <P></P>
  75. <DT><STRONG><A NAME="item_eof">$p->eof</A></STRONG><BR>
  76. <DD>
  77. Signals end of document.  Call <A HREF="#item_eof"><CODE>eof()</CODE></A> to flush any remaining buffered
  78. text.  The return value is a reference to the parser object.
  79. <P></P>
  80. <DT><STRONG><A NAME="item_parse_file">$p->parse_file( $file );</A></STRONG><BR>
  81. <DD>
  82. This method can be called to parse text from a file.  The argument can
  83. be a filename or an already opened file handle. The return value from
  84. <A HREF="#item_parse_file"><CODE>parse_file()</CODE></A> is a reference to the parser object.
  85. <P></P>
  86. <DT><STRONG><A NAME="item_strict_comment">$p->strict_comment( [$bool] )</A></STRONG><BR>
  87. <DD>
  88. By default we parse comments similar to how the popular browsers (like
  89. Netscape and MSIE) do it.  This means that comments will always be
  90. terminated by the first occurrence of ``-->''.  This is not correct
  91. according to the ``official'' HTML standards.  The official behaviour
  92. can be enabled by calling the <A HREF="#item_strict_comment"><CODE>strict_comment()</CODE></A> method with a TRUE
  93. argument.
  94. <P>The return value from <A HREF="#item_strict_comment"><CODE>strict_comment()</CODE></A> is the old attribute value.</P>
  95. <P></P></DL>
  96. <P>In order to make the parser do anything interesting, you must make a
  97. subclass where you override one or more of the following methods as
  98. appropriate:</P>
  99. <DL>
  100. <DT><STRONG><A NAME="item_declaration">$self-><CODE>declaration($decl)</CODE></A></STRONG><BR>
  101. <DD>
  102. This method is called when a <EM>markup declaration</EM> has been
  103. recognized.  For typical HTML documents, the only declaration you are
  104. likely to find is <!DOCTYPE ...>.  The initial ``<!'' and ending ``>'' is
  105. not part of the string passed as argument.  Comments are removed and
  106. entities will <STRONG>not</STRONG> be expanded.
  107. <P></P>
  108. <DT><STRONG><A NAME="item_start">$self->start($tag, $attr, $attrseq, $origtext)</A></STRONG><BR>
  109. <DD>
  110. This method is called when a complete start tag has been recognized.
  111. The first argument is the tag name (in lower case) and the second
  112. argument is a reference to a hash that contain all attributes found
  113. within the start tag.  The attribute keys are converted to lower case.
  114. Entities found in the attribute values are already expanded.  The
  115. third argument is a reference to an array with the lower case
  116. attribute keys in the original order.  The fourth argument is the
  117. original HTML text.
  118. <P></P>
  119. <DT><STRONG><A NAME="item_end">$self->end($tag, $origtext)</A></STRONG><BR>
  120. <DD>
  121. This method is called when an end tag has been recognized.  The
  122. first argument is the lower case tag name, the second the original
  123. HTML text of the tag.
  124. <P></P>
  125. <DT><STRONG><A NAME="item_text">$self-><CODE>text($text)</CODE></A></STRONG><BR>
  126. <DD>
  127. This method is called when plain text in the document is recognized.
  128. The text is passed on unmodified and might contain multiple lines.
  129. Note that for efficiency reasons entities in the text are <STRONG>not</STRONG>
  130. expanded.  You should call HTML::Entities::decode($text) before you
  131. process the text any further.
  132. <P>A sequence of text in the HTML document can be broken between several
  133. invocations of $self->text.  The parser will make sure that it does
  134. not break a word or a sequence of spaces between two invocations of
  135. $self->text().</P>
  136. <P></P>
  137. <DT><STRONG><A NAME="item_comment">$self-><CODE>comment($comment)</CODE></A></STRONG><BR>
  138. <DD>
  139. This method is called as comments are recognized.  The leading and
  140. trailing ``--'' sequences have been stripped off the comment text.
  141. <P></P></DL>
  142. <P>The default implementation of these methods do nothing, i.e., the
  143. tokens are just ignored.</P>
  144. <P>There is really nothing in the basic parser that is HTML specific, so
  145. it is likely that the parser can parse other kinds of SGML documents.
  146. SGML has many obscure features (not implemented by this module) that
  147. prevent us from renaming this module as <CODE>SGML::Parser</CODE>.</P>
  148. <P>
  149. <HR>
  150. <H1><A NAME="efficiency">EFFICIENCY</A></H1>
  151. <P>The parser is fairly inefficient if the chunks passed to $p-><A HREF="#item_parse"><CODE>parse()</CODE></A>
  152. are too big.  The reason is probably that perl ends up with a lot of
  153. character copying when tokens are removed from the beginning of the
  154. strings.  A chunk size of about 256-512 bytes was optimal in a test I
  155. made with some real world HTML documents.  (The parser was about 3
  156. times slower with a chunk size of 20K).</P>
  157. <P>
  158. <HR>
  159. <H1><A NAME="see also">SEE ALSO</A></H1>
  160. <P><A HREF="../../../site/lib/HTML/Entities.html">the HTML::Entities manpage</A>, <A HREF="../../../site/lib/HTML/TokeParser.html">the HTML::TokeParser manpage</A>, <A HREF="../../../site/lib/HTML/Filter.html">the HTML::Filter manpage</A>,
  161. <A HREF="../../../site/lib/HTML/HeadParser.html">the HTML::HeadParser manpage</A>, <A HREF="../../../site/lib/HTML/LinkExtor.html">the HTML::LinkExtor manpage</A></P>
  162. <P><A HREF="../../../site/lib/HTML/TreeBuilder.html">the HTML::TreeBuilder manpage</A> (part of the <EM>HTML-Tree</EM> distribution)</P>
  163. <P>
  164. <HR>
  165. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  166. <P>Copyright 1996-1999 Gisle Aas. All rights reserved.</P>
  167. <P>This library is free software; you can redistribute it and/or
  168. modify it under the same terms as Perl itself.</P>
  169. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  170. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  171. <STRONG><P CLASS=block> HTML::Parser - SGML parser class</P></STRONG>
  172. </TD></TR>
  173. </TABLE>
  174.  
  175. </BODY>
  176.  
  177. </HTML>
  178.