home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_e12390eb6ce0f01d6ce7beee8cdd94ac
< prev
next >
Wrap
Text File
|
2000-03-23
|
8KB
|
209 lines
<HTML>
<HEAD>
<TITLE>HTML::Element - Class for objects that represent HTML elements</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> HTML::Element - Class for objects that represent HTML elements</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#bugs">BUGS</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>HTML::Element - Class for objects that represent HTML elements</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
require HTML::Element;
$a = new HTML::Element 'a', href => '<A HREF="http://www.oslonett.no/">http://www.oslonett.no/</A>';
$a->push_content("Oslonett AS");</PRE>
<PRE>
$tag = $a->tag;
$tag = $a->starttag;
$tag = $a->endtag;
$ref = $a->attr('href');</PRE>
<PRE>
$links = $a->extract_links();</PRE>
<PRE>
print $a->as_HTML;</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>Objects of the HTML::Element class can be used to represent elements
of HTML. These objects have attributes and content. The content is an
array of text segments and other HTML::Element objects. Thus a
tree of HTML::Element objects as nodes can represent the syntax tree
for a HTML document.</P>
<P>The following methods are available:</P>
<DL>
<DT><STRONG><A NAME="item_new">$h = HTML::Element->new('tag', 'attrname' => 'value',...)</A></STRONG><BR>
<DD>
The object constructor. Takes a tag name as argument. Optionally,
allows you to specify initial attributes at object creation time.
<P></P>
<DT><STRONG><A NAME="item_tag">$h-><CODE>tag()</CODE></A></STRONG><BR>
<DD>
Returns (optionally sets) the tag name for the element. The tag is
always converted to lower case.
<P></P>
<DT><STRONG><A NAME="item_starttag">$h-><CODE>starttag()</CODE></A></STRONG><BR>
<DD>
Returns the complete start tag for the element. Including leading
``<'', trailing ``>'' and attributes.
<P></P>
<DT><STRONG><A NAME="item_endtag">$h-><CODE>endtag()</CODE></A></STRONG><BR>
<DD>
Returns the complete end tag. Includes leading ``</'' and the trailing
``>''.
<P></P>
<DT><STRONG><A NAME="item_parent">$h-><CODE>parent([$newparent])</CODE></A></STRONG><BR>
<DD>
Returns (optionally sets) the parent for this element.
<P></P>
<DT><STRONG><A NAME="item_implicit">$h-><CODE>implicit([$bool])</CODE></A></STRONG><BR>
<DD>
Returns (optionally sets) the implicit attribute. This attribute is
used to indicate that the element was not originally present in the
source, but was inserted in order to conform to HTML strucure.
<P></P>
<DT><STRONG><A NAME="item_is_inside">$h-><CODE>is_inside('tag',...)</CODE></A></STRONG><BR>
<DD>
Returns true if this tag is contained inside one of the specified tags.
<P></P>
<DT><STRONG><A NAME="item_pos">$h-><CODE>pos()</CODE></A></STRONG><BR>
<DD>
Returns (and optionally sets) the current position. The position is a
reference to a HTML::Element object that is part of the tree that has
the current object as root. This restriction is not enforced when
setting pos(), but unpredictable things will happen if this is not
true.
<P></P>
<DT><STRONG><A NAME="item_attr">$h->attr('attr', [$value])</A></STRONG><BR>
<DD>
Returns (and optionally sets) the value of some attribute.
<P></P>
<DT><STRONG><A NAME="item_content">$h-><CODE>content()</CODE></A></STRONG><BR>
<DD>
Returns the content of this element. The content is represented as a
reference to an array of text segments and references to other
HTML::Element objects.
<P></P>
<DT><STRONG><A NAME="item_is_empty">$h-><CODE>is_empty()</CODE></A></STRONG><BR>
<DD>
Returns true if there is no content.
<P></P>
<DT><STRONG><A NAME="item_insert_element">$h->insert_element($element, $implicit)</A></STRONG><BR>
<DD>
Inserts a new element at current position and updates <A HREF="#item_pos"><CODE>pos()</CODE></A> to point
to the inserted element. Returns $element.
<P></P>
<DT><STRONG><A NAME="item_push_content">$h-><CODE>push_content($element_or_text,...)</CODE></A></STRONG><BR>
<DD>
Adds to the content of the element. The content should be a text
segment (scalar) or a reference to a HTML::Element object.
<P></P>
<DT><STRONG><A NAME="item_delete_content">$h-><CODE>delete_content()</CODE></A></STRONG><BR>
<DD>
Clears the content.
<P></P>
<DT><STRONG><A NAME="item_delete">$h-><CODE>delete()</CODE></A></STRONG><BR>
<DD>
Frees memory associated with the element and all children. This is
needed because perl's reference counting does not work since we use
circular references.
<P></P>
<DT><STRONG><A NAME="item_traverse">$h->traverse(\&callback, [$ignoretext])</A></STRONG><BR>
<DD>
Traverse the element and all of its children. For each node visited, the
callback routine is called with the node, a startflag and the depth as
arguments. If the $ignoretext parameter is true, then the callback
will not be called for text content. The flag is 1 when we enter a
node and 0 when we leave the node.
<P>If the returned value from the callback is false then we will not
traverse the children.</P>
<P></P>
<DT><STRONG><A NAME="item_extract_links">$h-><CODE>extract_links([@wantedTypes])</CODE></A></STRONG><BR>
<DD>
Returns links found by traversing the element and all of its children.
The return value is a reference to an array. Each element of the
array is an array with 2 values; the link value and a reference to the
corresponding element.
<P>You might specify that you just want to extract some types of links.
For instance if you only want to extract <a href=``...''> and <img
src=``...''> links you might code it like this:</P>
<PRE>
for (@{ $e->extract_links(qw(a img)) }) {
($link, $linkelem) = @$_;
...
}</PRE>
<P></P>
<DT><STRONG><A NAME="item_dump">$h-><CODE>dump()</CODE></A></STRONG><BR>
<DD>
Prints the element and all its children to STDOUT. Mainly useful for
debugging. The structure of the document is shown by indentation (no
end tags).
<P></P>
<DT><STRONG><A NAME="item_as_HTML">$h-><CODE>as_HTML()</CODE></A></STRONG><BR>
<DD>
Returns a string (the HTML document) that represents the element and
its children.
<P></P></DL>
<P>
<HR>
<H1><A NAME="bugs">BUGS</A></H1>
<P>If you want to free the memory assosiated with a tree built of
HTML::Element nodes then you will have to delete it explicitly. The
reason for this is that perl currently has no proper garbage
collector, but depends on reference counts in the objects. This
scheme fails because the parse tree contains circular references
(parents have references to their children and children have a
reference to their parent).</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="../../../site/lib/HTML/AsSubs.html">the HTML::AsSubs manpage</A></P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright 1995-1998 Gisle Aas.</P>
<P>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> HTML::Element - Class for objects that represent HTML elements</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>