1XML::LibXML::Text(3) User Contributed Perl Documentation XML::LibXML::Text(3)
2
3
4
6 XML::LibXML::Text - XML::LibXML Class for Text Nodes
7
9 use XML::LibXML;
10 # Only methods specific to Text nodes are listed here,
11 # see the XML::LibXML::Node manpage for other methods
12
13 $text = XML::LibXML::Text->new( $content );
14 $nodedata = $text->data;
15 $text->setData( $text_content );
16 $text->substringData($offset, $length);
17 $text->appendData( $somedata );
18 $text->insertData($offset, $string);
19 $text->deleteData($offset, $length);
20 $text->deleteDataString($remstring, $all);
21 $text->replaceData($offset, $length, $string);
22 $text->replaceDataString($old, $new, $flag);
23 $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
24
26 Unlike the DOM specification, XML::LibXML implements the text node as
27 the base class of all character data node. Therefore there exists no
28 CharacterData class. This allows one to apply methods of text nodes
29 also to Comments and CDATA-sections.
30
32 The class inherits from XML::LibXML::Node. The documentation for
33 Inherited methods is not listed here.
34
35 Many functions listed here are extensively documented in the DOM Level
36 3 specification (<http://www.w3.org/TR/DOM-Level-3-Core/>). Please
37 refer to the specification for extensive documentation.
38
39 new
40 $text = XML::LibXML::Text->new( $content );
41
42 The constructor of the class. It creates an unbound text node.
43
44 data
45 $nodedata = $text->data;
46
47 Although there exists the "nodeValue" attribute in the Node class,
48 the DOM specification defines data as a separate attribute.
49 "XML::LibXML" implements these two attributes not as different
50 attributes, but as aliases, such as "libxml2" does. Therefore
51
52 $text->data;
53
54 and
55
56 $text->nodeValue;
57
58 will have the same result and are not different entities.
59
60 setData($string)
61 $text->setData( $text_content );
62
63 This function sets or replaces text content to a node. The node has
64 to be of the type "text", "cdata" or "comment".
65
66 substringData($offset,$length)
67 $text->substringData($offset, $length);
68
69 Extracts a range of data from the node. (DOM Spec) This function
70 takes the two parameters $offset and $length and returns the sub-
71 string, if available.
72
73 If the node contains no data or $offset refers to an non-existing
74 string index, this function will return undef. If $length is out of
75 range "substringData" will return the data starting at $offset
76 instead of causing an error.
77
78 appendData($string)
79 $text->appendData( $somedata );
80
81 Appends a string to the end of the existing data. If the current
82 text node contains no data, this function has the same effect as
83 "setData".
84
85 insertData($offset,$string)
86 $text->insertData($offset, $string);
87
88 Inserts the parameter $string at the given $offset of the existing
89 data of the node. This operation will not remove existing data, but
90 change the order of the existing data.
91
92 The $offset has to be a positive value. If $offset is out of range,
93 "insertData" will have the same behaviour as "appendData".
94
95 deleteData($offset, $length)
96 $text->deleteData($offset, $length);
97
98 This method removes a chunk from the existing node data at the
99 given offset. The $length parameter tells, how many characters
100 should be removed from the string.
101
102 deleteDataString($string, [$all])
103 $text->deleteDataString($remstring, $all);
104
105 This method removes a chunk from the existing node data. Since the
106 DOM spec is quite unhandy if you already know "which" string to
107 remove from a text node, this method allows more perlish code :)
108
109 The functions takes two parameters: $string and optional the $all
110 flag. If $all is not set, undef or 0, "deleteDataString" will
111 remove only the first occurrence of $string. If $all is
112 TRUE"deleteDataString" will remove all occurrences of $string from
113 the node data.
114
115 replaceData($offset, $length, $string)
116 $text->replaceData($offset, $length, $string);
117
118 The DOM style version to replace node data.
119
120 replaceDataString($oldstring, $newstring, [$all])
121 $text->replaceDataString($old, $new, $flag);
122
123 The more programmer friendly version of replaceData() :)
124
125 Instead of giving offsets and length one can specify the exact
126 string ($oldstring) to be replaced. Additionally the $all flag
127 allows one to replace all occurrences of $oldstring.
128
129 replaceDataRegEx( $search_cond, $replace_cond, $reflags )
130 $text->replaceDataRegEx( $search_cond, $replace_cond, $reflags );
131
132 This method replaces the node's data by a "simple" regular
133 expression. Optional, this function allows one to pass some flags
134 that will be added as flag to the replace statement.
135
136 NOTE: This is a shortcut for
137
138 my $datastr = $node->getData();
139 $datastr =~ s/somecond/replacement/g; # 'g' is just an example for any flag
140 $node->setData( $datastr );
141
142 This function can make things easier to read for simple
143 replacements. For more complex variants it is recommended to use
144 the code snippet above.
145
147 Matt Sergeant, Christian Glahn, Petr Pajas
148
150 2.0207
151
153 2001-2007, AxKit.com Ltd.
154
155 2002-2006, Christian Glahn.
156
157 2006-2009, Petr Pajas.
158
160 This program is free software; you can redistribute it and/or modify it
161 under the same terms as Perl itself.
162
163
164
165perl v5.34.0 2021-07-23 XML::LibXML::Text(3)