|
HTML::TagUtil - Perl Utility for HTML tags |
HTML::TagUtil - Perl Utility for HTML tags
use HTML::TagUtil; $_ = ``<i>Now!</i>'';
my $tagger = HTML::TagUtil->new(); print ``Tagged!'' if ($tagger->tagged()); print ``Open Tagged!'' if ($tagger->opentagged()); print ``Close Tagged!'' if ($tagger->closetagged());
HTML::TagUtil is a perl module providing a Object-Oriented interface to getting information about HTML/SGML/XML tags and their attributes and content.
also, you can supply an optional argument as the string to use if none is given to one of the methods. if you do not supply it here, it defaults to the default variable ($_) here and everywhere else.
$_ = ``<html>html stuff</html>''; print ``Tagged'' if ($tagger->tagged); #prints ``Tagged'' $_ = ``<html>html stuff''; print ``Tagged'' if ($tagger->tagged); #prints nothing. $_ = ``html stuff</html>''; print ``Tagged'' if ($tagger->tagged); #prints nothing. $_ = ``<html blah=''blah_blah``>html stuff</html>''; print ``Tagged'' if ($tagger->tagged); #prints ``Tagged''
tagged can handle attributes and empty elements.
$_ = ``<html>stuff''; print ``Open Tagged'' if ($tagger->opentagged); #prints ``Open Tagged'' $_ = ``<html>stuff</html>''; print ``Open Tagged'' if ($tagger->opentagged); #prints ``Open Tagged'' $_ = ``stuff</html>''; print ``Open Tagged'' if ($tagger->openedtagged); prints nothing $_ = ``<html some=''cool`` attributes=''yes``>stuff''; print ``Open Tagged'' if ($tagger->opentagged); #prints ``Open Tagged''
opentagged can handle attributes as well as empty elements.
$_ = ``stuff</html>''; print ``Close Tagged'' if ($tagger->closetagged); #prints ``Closed Tagged'' $_ = ``<html>stuff</html>''; print ``Close Tagged'' if ($tagger->closetagged); #prints ``Closed Tagged'' $_ = ``<html>stuff''; print ``Closed Tagged'' if ($tagger->closetagged); #prints nothing. $_ = ``stuff</html stuff=''cool``>''; print ``Closed Tagged'' if ($tagger->closetagged); #prints nothing.
closedtagged can not handle attributes or empty elements. because end tags can't have attributes or be empty.
$_ = ``<html>stuff</html>''; my $pos = $tagger->tagpos ($_, '<html>', 0); print $pos; #prints ``1'' $_ = ``<html>stuff</html>''; my $pos = $tagger->tagpos ($_, 'html', 0); print $pos; #prints ``1'' because the < and > get added on to the 'html'. $_ = ``stuff<html>''; my $pos = $tagger->tagpos ($_, '<html>', 0); print $pos; #prints ``6'' because counting starts from one for this. $_ = ``stuff<html>''; my $pos = $tagger->tagpos ($_, 'html', 0); print $pos; #prints ``6'' again because counting starts from one for this.
tagpos can handle anything that is surrounded by < and >.
$_ = ``<img />''; print ``Empty'' if ($tagger->empty); #prints ``Empty'' $_ = ``<img/>''; print ``Empty'' if ($tagger->empty); #prints ``Empty'' $_ = ``<img></img>''; print ``Empty'' if ($tagger->empty); #prints nothing $_ = ``<img src=\''http://www.example.com/cool.gif\`` />''; print ``Empty'' if ($tagger->empty); #prints ``Empty''
empty can handle attributes and varying amounts of space before the end tag.
allow_hyphen(1) or setting
$HTML::TagUtil::Allow_Hyphen to 1. (Not recommended.)
Some examples are:
$_ = "<!--comment here-->"; print "Comment" if ($tagger->comment); #prints "Comment" $_ = "<!---comment-here-->"; print "Comment" if ($tagger->comment); #prints nothing. $HTML::TagUtil::Allow_Hyphen = 1; $_ = "<!---comment-here-->"; print "Comment" if ($tagger->comment); #prints "Comment"
comment can handle anything in between '<!--' and '-->', with the option of allowing hyphens in the comment.
none. (OO)
none known.
the HTML::Parser manpage the HTML::Tagset manpage
HTML::TagUtil's website is http://www.x-tac.net/html-util.htm/
<nightcat>, <nightcat@crocker.com>
Copyright 2005 by <nightcat>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
HTML::TagUtil - Perl Utility for HTML tags |