Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.7 KiB

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