home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Text.pod < prev    next >
Encoding:
Text File  |  2003-08-22  |  4.8 KB  |  219 lines

  1. =head1 NAME
  2.  
  3. XML::LibXML::Text - XML::LibXML Class for Text Nodes
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.   $text = XML::LibXML::Text->new( $content ); 
  8.   $nodedata = $text->data;
  9.   $text->setData( $text_content );
  10.   $text->substringData($offset, $length);
  11.   $text->appendData( $somedata );
  12.   $text->insertData($offset, $string);
  13.   $text->deleteData($offset, $length);
  14.   $text->deleteDataString($remstring, $all);
  15.   $text->replaceData($offset, $length, $string);
  16.   $text->replaceDataString($old, $new, $flag);
  17.   $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
  18.  
  19.  
  20. =head1 DESCRIPTION
  21.  
  22. Different to the DOM specification XML::LibXML implements the text node as the
  23. base class of all character data node. Therefor there exists no CharacterData
  24. class. This allow one to use all methods that are available for textnodes as
  25. well for Comments or CDATA-sections.
  26.  
  27. =over 4
  28.  
  29. =item B<new>
  30.  
  31.   $text = XML::LibXML::Text->new( $content ); 
  32.  
  33. The constuctor of the class. It creates an unbound text node.
  34.  
  35.  
  36.  
  37. =back
  38.  
  39. =over 4
  40.  
  41. =item B<data>
  42.  
  43.   $nodedata = $text->data;
  44.  
  45. Although there exists the nodeValue attribute in the Node class, the DOM
  46. specification defines data as a separate attribute. XML::LibXML implements
  47. these two attributes not as different attributes, but as aliases, such as
  48. libxml2 does. Therefore
  49.  
  50.    $text->data;
  51.  
  52. and
  53.  
  54.    $text->nodeValue;
  55.  
  56. will have the same result and are not different entities.
  57.  
  58.  
  59.  
  60. =back
  61.  
  62. =over 4
  63.  
  64. =item B<setData($string)>
  65.  
  66.   $text->setData( $text_content );
  67.  
  68. This function sets or replaces text content to a node. The node has to be of
  69. the type "text", "cdata" or "comment".
  70.  
  71.  
  72.  
  73. =back
  74.  
  75. =over 4
  76.  
  77. =item B<substringData($offset,$length)>
  78.  
  79.   $text->substringData($offset, $length);
  80.  
  81. Extracts a range of data from the node. (DOM Spec) This function takes the two
  82. parameters $offset and $length and returns the substring if available.
  83.  
  84. If the node contains no data or $offset referes to an nonexisting string index,
  85. this function will return undef. If $length is out of range substringData will
  86. return the data starting at $offset instead of causing an error.
  87.  
  88.  
  89.  
  90. =back
  91.  
  92. =over 4
  93.  
  94. =item B<appendData($string)>
  95.  
  96.   $text->appendData( $somedata );
  97.  
  98. Appends a string to the end of the existing data. If the current text node
  99. contains no data, this function has the same effect as setData.
  100.  
  101.  
  102.  
  103. =back
  104.  
  105. =over 4
  106.  
  107. =item B<insertData($offset,$string)>
  108.  
  109.   $text->insertData($offset, $string);
  110.  
  111. Inserts the parameter $string at the given $offset of the existing data of the
  112. node. This operation will not remove existing data, but change the order of the
  113. existing data.
  114.  
  115. The $offset has to be a positive value. If $offset is out of range, insertData
  116. will have the same behaviour as appendData.
  117.  
  118.  
  119.  
  120. =back
  121.  
  122. =over 4
  123.  
  124. =item B<deleteData($offset, $length)>
  125.  
  126.   $text->deleteData($offset, $length);
  127.  
  128. This method removes a chunk from the existing node data at the given offset.
  129. The $length parameter tells, how many characters should be removed from the
  130. string.
  131.  
  132.  
  133.  
  134. =back
  135.  
  136. =over 4
  137.  
  138. =item B<deleteDataString($string, [$all])>
  139.  
  140.   $text->deleteDataString($remstring, $all);
  141.  
  142. This method removes a chunk from the existing node data. Since the DOM spec is
  143. quite unhandy if you already know which string to remove from a text node, this
  144. method allows more perlish code :)
  145.  
  146. The functions takes two parameters: $string and optional the $all flag. If $all
  147. is not set, undef or 0, deleteDataString will remove only the first occourance
  148. of $string. If $all is TRUE deleteDataString will remove all occourences of
  149. $string from the node data.
  150.  
  151.  
  152.  
  153. =back
  154.  
  155. =over 4
  156.  
  157. =item B<replaceData($offset, $length, $string)>
  158.  
  159.   $text->replaceData($offset, $length, $string);
  160.  
  161. The DOM style version to replace node data.
  162.  
  163.  
  164.  
  165. =back
  166.  
  167. =over 4
  168.  
  169. =item B<replaceDataString($oldstring, $newstring, [$all])>
  170.  
  171.   $text->replaceDataString($old, $new, $flag);
  172.  
  173. The more programmer friendly version of replaceData() :)
  174.  
  175. Instead of giving offsets and length one can specify the exact string
  176. ($oldstring) to be replaced. Additionally the $all flag allows to replace all
  177. occourences of $oldstring.
  178.  
  179.  
  180.  
  181. =back
  182.  
  183. =over 4
  184.  
  185. =item B<replaceDataRegEx( $search_cond, $replace_cond, $reflags )>
  186.  
  187.   $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
  188.  
  189. This method replaces the node's data by a simple regular expression. Optional,
  190. this function allows to pass some flags that will be added as flag to the
  191. replace statement.
  192.  
  193. NOTE: This is a shortcut for
  194.  
  195.    my $datastr = $node->getData();
  196.    $datastr =~ s/somecond/replacement/g; # 'g' is just an example for any flag
  197.    $node->setData( $datastr );
  198.  
  199. This function can make things easier to read for simple replacements. For more
  200. complex variants it is recommented to use the code snippet above.
  201.  
  202.  
  203.  
  204. =back
  205.  
  206. =head1 AUTHORS
  207.  
  208. Matt Sergeant, 
  209. Christian Glahn, 
  210. =head1 VERSION
  211.  
  212. 1.56
  213.  
  214. =head1 COPYRIGHT
  215.  
  216. 2001-2002, AxKit.com Ltd; 2001-2003 Christian Glahn, All rights reserved.
  217.  
  218. =cut
  219.