home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _cb3db5bbc985dd8fc6e4c1f805e55b8d < prev    next >
Encoding:
Text File  |  2004-06-01  |  3.7 KB  |  153 lines

  1.  
  2. require 5;
  3. package HTML::Parse;
  4.   # Time-stamp: "2000-05-18 23:40:06 MDT"
  5.  
  6. =head1 NAME
  7.  
  8. HTML::Parse - Deprecated, a wrapper around HTML::TreeBuilder
  9.  
  10. =head1 SYNOPSIS
  11.  
  12.   See the documentation for HTML::TreeBuilder
  13.  
  14. =head1 DESCRIPTION
  15.  
  16. Disclaimer: This module is provided only for backwards compatibility
  17. with earlier versions of this library.  New code should I<not> use
  18. this module, and should really use the HTML::Parser and
  19. HTML::TreeBuilder modules directly, instead.
  20.  
  21. The C<HTML::Parse> module provides functions to parse HTML documents.
  22. There are two functions exported by this module:
  23.  
  24. =over 4
  25.  
  26. =item parse_html($html) or parse_html($html, $obj)
  27.  
  28. This function is really just a synonym for $obj->parse($html) and $obj
  29. is assumed to be a subclass of C<HTML::Parser>.  Refer to
  30. L<HTML::Parser> for more documentation.
  31.  
  32. If $obj is not specified, the $obj will default to an internally
  33. created new C<HTML::TreeBuilder> object configured with strict_comment()
  34. turned on.  That class implements a parser that builds (and is) a HTML
  35. syntax tree with HTML::Element objects as nodes.
  36.  
  37. The return value from parse_html() is $obj.
  38.  
  39. =item parse_htmlfile($file, [$obj])
  40.  
  41. Same as parse_html(), but pulls the HTML to parse, from the named file.
  42.  
  43. Returns C<undef> if the file could not be opened, or $obj otherwise.
  44.  
  45. =back
  46.  
  47. When a C<HTML::TreeBuilder> object is created, the following variables
  48. control how parsing takes place:
  49.  
  50. =over 4
  51.  
  52. =item $HTML::Parse::IMPLICIT_TAGS
  53.  
  54. Setting this variable to true will instruct the parser to try to
  55. deduce implicit elements and implicit end tags.  If this variable is
  56. false you get a parse tree that just reflects the text as it stands.
  57. Might be useful for quick & dirty parsing.  Default is true.
  58.  
  59. Implicit elements have the implicit() attribute set.
  60.  
  61. =item $HTML::Parse::IGNORE_UNKNOWN
  62.  
  63. This variable contols whether unknow tags should be represented as
  64. elements in the parse tree.  Default is true.
  65.  
  66. =item $HTML::Parse::IGNORE_TEXT
  67.  
  68. Do not represent the text content of elements.  This saves space if
  69. all you want is to examine the structure of the document.  Default is
  70. false.
  71.  
  72. =item $HTML::Parse::WARN
  73.  
  74. Call warn() with an apropriate message for syntax errors.  Default is
  75. false.
  76.  
  77. =back
  78.  
  79. =head1 REMEMBER!
  80.  
  81. HTML::TreeBuilder objects should be explicitly destroyed when you're
  82. finished with them.  See L<HTML::TreeBuilder>.
  83.  
  84. =head1 SEE ALSO
  85.  
  86. L<HTML::Parser>, L<HTML::TreeBuilder>, L<HTML::Element>
  87.  
  88. =head1 COPYRIGHT
  89.  
  90. Copyright 1995-1998 Gisle Aas. All rights reserved.
  91.  
  92. This library is free software; you can redistribute it and/or
  93. modify it under the same terms as Perl itself.
  94.  
  95. =head1 AUTHOR
  96.  
  97. Gisle Aas E<lt>gisle@aas.noE<gt>.  Current maintainer
  98. Sean M. Burke E<lt>sburke@cpan.orgE<gt>
  99.  
  100. =cut
  101.  
  102.  
  103. require Exporter;
  104. @ISA = qw(Exporter);
  105. @EXPORT = qw(parse_html parse_htmlfile);
  106.  
  107. use strict;
  108. use vars qw($VERSION
  109.             $IMPLICIT_TAGS $IGNORE_UNKNOWN $IGNORE_TEXT $WARN
  110.            );
  111.  
  112. # Backwards compatability
  113. $IMPLICIT_TAGS  = 1;
  114. $IGNORE_UNKNOWN = 1;
  115. $IGNORE_TEXT    = 0;
  116. $WARN           = 0;
  117.  
  118. require HTML::TreeBuilder;
  119.  
  120. $VERSION = '2.71';
  121.  
  122.  
  123. sub parse_html ($;$)
  124. {
  125.     my $p = $_[1];
  126.     $p = _new_tree_maker() unless $p;
  127.     $p->parse($_[0]);
  128. }
  129.  
  130.  
  131. sub parse_htmlfile ($;$)
  132. {
  133.     my($file, $p) = @_;
  134.     local(*HTML);
  135.     open(HTML, $file) or return undef;
  136.     $p = _new_tree_maker() unless $p;
  137.     $p->parse_file(\*HTML);
  138. }
  139.  
  140. sub _new_tree_maker
  141. {
  142.     my $p = HTML::TreeBuilder->new(
  143.       implicit_tags  => $IMPLICIT_TAGS,
  144.       ignore_unknown => $IGNORE_UNKNOWN,
  145.       ignore_text    => $IGNORE_TEXT,
  146.       'warn'         => $WARN,
  147.     );
  148.     $p->strict_comment(1);
  149.     $p;
  150. }
  151.  
  152. 1;
  153.