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