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 >
Text File  |  2000-03-23  |  8KB  |  209 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>HTML::Element - Class for objects that represent HTML elements</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::Element - Class for objects that represent HTML elements</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="#bugs">BUGS</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::Element - Class for objects that represent HTML elements</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::Element;
  47.  $a = new HTML::Element 'a', href => '<A HREF="http://www.oslonett.no/">http://www.oslonett.no/</A>';
  48.  $a->push_content("Oslonett AS");</PRE>
  49. <PRE>
  50.  $tag = $a->tag;
  51.  $tag = $a->starttag;
  52.  $tag = $a->endtag;
  53.  $ref = $a->attr('href');</PRE>
  54. <PRE>
  55.  $links = $a->extract_links();</PRE>
  56. <PRE>
  57.  print $a->as_HTML;</PRE>
  58. <P>
  59. <HR>
  60. <H1><A NAME="description">DESCRIPTION</A></H1>
  61. <P>Objects of the HTML::Element class can be used to represent elements
  62. of HTML.  These objects have attributes and content.  The content is an
  63. array of text segments and other HTML::Element objects.  Thus a
  64. tree of HTML::Element objects as nodes can represent the syntax tree
  65. for a HTML document.</P>
  66. <P>The following methods are available:</P>
  67. <DL>
  68. <DT><STRONG><A NAME="item_new">$h = HTML::Element->new('tag', 'attrname' => 'value',...)</A></STRONG><BR>
  69. <DD>
  70. The object constructor.  Takes a tag name as argument. Optionally,
  71. allows you to specify initial attributes at object creation time.
  72. <P></P>
  73. <DT><STRONG><A NAME="item_tag">$h-><CODE>tag()</CODE></A></STRONG><BR>
  74. <DD>
  75. Returns (optionally sets) the tag name for the element.  The tag is
  76. always converted to lower case.
  77. <P></P>
  78. <DT><STRONG><A NAME="item_starttag">$h-><CODE>starttag()</CODE></A></STRONG><BR>
  79. <DD>
  80. Returns the complete start tag for the element.  Including leading
  81. ``<'', trailing ``>'' and attributes.
  82. <P></P>
  83. <DT><STRONG><A NAME="item_endtag">$h-><CODE>endtag()</CODE></A></STRONG><BR>
  84. <DD>
  85. Returns the complete end tag.  Includes leading ``</'' and the trailing
  86. ``>''.
  87. <P></P>
  88. <DT><STRONG><A NAME="item_parent">$h-><CODE>parent([$newparent])</CODE></A></STRONG><BR>
  89. <DD>
  90. Returns (optionally sets) the parent for this element.
  91. <P></P>
  92. <DT><STRONG><A NAME="item_implicit">$h-><CODE>implicit([$bool])</CODE></A></STRONG><BR>
  93. <DD>
  94. Returns (optionally sets) the implicit attribute.  This attribute is
  95. used to indicate that the element was not originally present in the
  96. source, but was inserted in order to conform to HTML strucure.
  97. <P></P>
  98. <DT><STRONG><A NAME="item_is_inside">$h-><CODE>is_inside('tag',...)</CODE></A></STRONG><BR>
  99. <DD>
  100. Returns true if this tag is contained inside one of the specified tags.
  101. <P></P>
  102. <DT><STRONG><A NAME="item_pos">$h-><CODE>pos()</CODE></A></STRONG><BR>
  103. <DD>
  104. Returns (and optionally sets) the current position.  The position is a
  105. reference to a HTML::Element object that is part of the tree that has
  106. the current object as root.  This restriction is not enforced when
  107. setting pos(), but unpredictable things will happen if this is not
  108. true.
  109. <P></P>
  110. <DT><STRONG><A NAME="item_attr">$h->attr('attr', [$value])</A></STRONG><BR>
  111. <DD>
  112. Returns (and optionally sets) the value of some attribute.
  113. <P></P>
  114. <DT><STRONG><A NAME="item_content">$h-><CODE>content()</CODE></A></STRONG><BR>
  115. <DD>
  116. Returns the content of this element.  The content is represented as a
  117. reference to an array of text segments and references to other
  118. HTML::Element objects.
  119. <P></P>
  120. <DT><STRONG><A NAME="item_is_empty">$h-><CODE>is_empty()</CODE></A></STRONG><BR>
  121. <DD>
  122. Returns true if there is no content.
  123. <P></P>
  124. <DT><STRONG><A NAME="item_insert_element">$h->insert_element($element, $implicit)</A></STRONG><BR>
  125. <DD>
  126. Inserts a new element at current position and updates <A HREF="#item_pos"><CODE>pos()</CODE></A> to point
  127. to the inserted element.  Returns $element.
  128. <P></P>
  129. <DT><STRONG><A NAME="item_push_content">$h-><CODE>push_content($element_or_text,...)</CODE></A></STRONG><BR>
  130. <DD>
  131. Adds to the content of the element.  The content should be a text
  132. segment (scalar) or a reference to a HTML::Element object.
  133. <P></P>
  134. <DT><STRONG><A NAME="item_delete_content">$h-><CODE>delete_content()</CODE></A></STRONG><BR>
  135. <DD>
  136. Clears the content.
  137. <P></P>
  138. <DT><STRONG><A NAME="item_delete">$h-><CODE>delete()</CODE></A></STRONG><BR>
  139. <DD>
  140. Frees memory associated with the element and all children.  This is
  141. needed because perl's reference counting does not work since we use
  142. circular references.
  143. <P></P>
  144. <DT><STRONG><A NAME="item_traverse">$h->traverse(\&callback, [$ignoretext])</A></STRONG><BR>
  145. <DD>
  146. Traverse the element and all of its children.  For each node visited, the
  147. callback routine is called with the node, a startflag and the depth as
  148. arguments.  If the $ignoretext parameter is true, then the callback
  149. will not be called for text content.  The flag is 1 when we enter a
  150. node and 0 when we leave the node.
  151. <P>If the returned value from the callback is false then we will not
  152. traverse the children.</P>
  153. <P></P>
  154. <DT><STRONG><A NAME="item_extract_links">$h-><CODE>extract_links([@wantedTypes])</CODE></A></STRONG><BR>
  155. <DD>
  156. Returns links found by traversing the element and all of its children.
  157. The return value is a reference to an array.  Each element of the
  158. array is an array with 2 values; the link value and a reference to the
  159. corresponding element.
  160. <P>You might specify that you just want to extract some types of links.
  161. For instance if you only want to extract <a href=``...''> and <img
  162. src=``...''> links you might code it like this:</P>
  163. <PRE>
  164.   for (@{ $e->extract_links(qw(a img)) }) {
  165.       ($link, $linkelem) = @$_;
  166.       ...
  167.   }</PRE>
  168. <P></P>
  169. <DT><STRONG><A NAME="item_dump">$h-><CODE>dump()</CODE></A></STRONG><BR>
  170. <DD>
  171. Prints the element and all its children to STDOUT.  Mainly useful for
  172. debugging.  The structure of the document is shown by indentation (no
  173. end tags).
  174. <P></P>
  175. <DT><STRONG><A NAME="item_as_HTML">$h-><CODE>as_HTML()</CODE></A></STRONG><BR>
  176. <DD>
  177. Returns a string (the HTML document) that represents the element and
  178. its children.
  179. <P></P></DL>
  180. <P>
  181. <HR>
  182. <H1><A NAME="bugs">BUGS</A></H1>
  183. <P>If you want to free the memory assosiated with a tree built of
  184. HTML::Element nodes then you will have to delete it explicitly.  The
  185. reason for this is that perl currently has no proper garbage
  186. collector, but depends on reference counts in the objects.  This
  187. scheme fails because the parse tree contains circular references
  188. (parents have references to their children and children have a
  189. reference to their parent).</P>
  190. <P>
  191. <HR>
  192. <H1><A NAME="see also">SEE ALSO</A></H1>
  193. <P><A HREF="../../../site/lib/HTML/AsSubs.html">the HTML::AsSubs manpage</A></P>
  194. <P>
  195. <HR>
  196. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  197. <P>Copyright 1995-1998 Gisle Aas.</P>
  198. <P>This library is free software; you can redistribute it and/or
  199. modify it under the same terms as Perl itself.</P>
  200. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  201. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  202. <STRONG><P CLASS=block> HTML::Element - Class for objects that represent HTML elements</P></STRONG>
  203. </TD></TR>
  204. </TABLE>
  205.  
  206. </BODY>
  207.  
  208. </HTML>
  209.