1XML::LibXML::Text(3)  User Contributed Perl Documentation XML::LibXML::Text(3)
2
3
4

NAME

6       XML::LibXML::Text - XML::LibXML Class for Text Nodes
7

SYNOPSIS

9         $text = XML::LibXML::Text->new( $content );
10         $nodedata = $text->data;
11         $text->setData( $text_content );
12         $text->substringData($offset, $length);
13         $text->appendData( $somedata );
14         $text->insertData($offset, $string);
15         $text->deleteData($offset, $length);
16         $text->deleteDataString($remstring, $all);
17         $text->replaceData($offset, $length, $string);
18         $text->replaceDataString($old, $new, $flag);
19         $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
20

DESCRIPTION

22       Different to the DOM specification XML::LibXML implements the text node
23       as the base class of all character data node. Therefor there exists no
24       CharacterData class. This allow one to use all methods that are avail‐
25       able for textnodes as well for Comments or CDATA-sections.
26
27       new
28             $text = XML::LibXML::Text->new( $content );
29
30           The constuctor of the class. It creates an unbound text node.
31
32       data
33             $nodedata = $text->data;
34
35           Although there exists the nodeValue attribute in the Node class,
36           the DOM specification defines data as a separate attribute.
37           XML::LibXML implements these two attributes not as different
38           attributes, but as aliases, such as libxml2 does. Therefore
39
40              $text->data;
41
42           and
43
44              $text->nodeValue;
45
46           will have the same result and are not different entities.
47
48       setData($string)
49             $text->setData( $text_content );
50
51           This function sets or replaces text content to a node. The node has
52           to be of the type "text", "cdata" or "comment".
53
54       substringData($offset,$length)
55             $text->substringData($offset, $length);
56
57           Extracts a range of data from the node. (DOM Spec) This function
58           takes the two parameters $offset and $length and returns the sub‐
59           string, if available.
60
61           If the node contains no data or $offset refers to an nonexisting
62           string index, this function will return undef. If $length is out of
63           range substringData will return the data starting at $offset
64           instead of causing an error.
65
66       appendData($string)
67             $text->appendData( $somedata );
68
69           Appends a string to the end of the existing data. If the current
70           text node contains no data, this function has the same effect as
71           setData.
72
73       insertData($offset,$string)
74             $text->insertData($offset, $string);
75
76           Inserts the parameter $string at the given $offset of the existing
77           data of the node. This operation will not remove existing data, but
78           change the order of the existing data.
79
80           The $offset has to be a positive value. If $offset is out of range,
81           insertData will have the same behaviour as appendData.
82
83       deleteData($offset, $length)
84             $text->deleteData($offset, $length);
85
86           This method removes a chunk from the existing node data at the
87           given offset.  The $length parameter tells, how many characters
88           should be removed from the string.
89
90       deleteDataString($string, [$all])
91             $text->deleteDataString($remstring, $all);
92
93           This method removes a chunk from the existing node data. Since the
94           DOM spec is quite unhandy if you already know which string to
95           remove from a text node, this method allows more perlish code :)
96
97           The functions takes two parameters: $string and optional the $all
98           flag. If $all is not set, undef or 0, deleteDataString will remove
99           only the first occourance of $string. If $all is TRUE deleteDataS‐
100           tring will remove all occurrences of $string from the node data.
101
102       replaceData($offset, $length, $string)
103             $text->replaceData($offset, $length, $string);
104
105           The DOM style version to replace node data.
106
107       replaceDataString($oldstring, $newstring, [$all])
108             $text->replaceDataString($old, $new, $flag);
109
110           The more programmer friendly version of replaceData() :)
111
112           Instead of giving offsets and length one can specify the exact
113           string ($oldstring) to be replaced. Additionally the $all flag
114           allows to replace all occourences of $oldstring.
115
116       replaceDataRegEx( $search_cond, $replace_cond, $reflags )
117             $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
118
119           This method replaces the node's data by a simple regular expres‐
120           sion. Optional, this function allows to pass some flags that will
121           be added as flag to the replace statement.
122
123           NOTE: This is a shortcut for
124
125              my $datastr = $node->getData();
126              $datastr =~ s/somecond/replacement/g; # 'g' is just an example for any flag
127              $node->setData( $datastr );
128
129           This function can make things easier to read for simple replace‐
130           ments. For more complex variants it is recommended to use the code
131           snippet above.
132

AUTHORS

134       Matt Sergeant, Christian Glahn, Petr Pajas,
135

VERSION

137       1.62
138
140       2001-2006, AxKit.com Ltd; 2002-2006 Christian Glahn; 2006 Petr Pajas,
141       All rights reserved.
142
143
144
145perl v5.8.8                       2006-11-17              XML::LibXML::Text(3)
Impressum