line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
XML::TinyXML - Little and efficient Perl module to manage xml data. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use XML::TinyXML; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# First create an XML Context |
10
|
|
|
|
|
|
|
$xml = XML::TinyXML->new(); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# and add a root node |
13
|
|
|
|
|
|
|
$xml->addRootNode('nodelabel', 'somevalue', { attr1 => v1, attr2 => v2 }); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# if you want to reuse a previously created node object ... |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# ( you can create one calling : |
18
|
|
|
|
|
|
|
# * %attrs = ( attr1 => v1, attr2 => v2 ); |
19
|
|
|
|
|
|
|
# * $node = XML::TinyXML::Node->new('nodelabel', param => 'somevalue', attrs => \%attrs); |
20
|
|
|
|
|
|
|
# ) |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# the new XML Context can be created giving the root node directly to the constructor |
23
|
|
|
|
|
|
|
$xml = XML::TinyXML->new($node); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# A better (and easier) option is also to let the context constructor create the rootnode for you: |
28
|
|
|
|
|
|
|
$xml = XML::TinyXML->new('rootnode', param => 'somevalue', attrs => { attr1 => v1, attr2 => v2 }); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# an empty root node can be created as well: |
31
|
|
|
|
|
|
|
$xml = XML::TinyXML->new('rootnode'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# You can later obtain a reference to the node object using the getNode() method |
34
|
|
|
|
|
|
|
$node = $xml->getNode('/rootnode'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# the leading '/' is optional ... since all paths will be considered absolute and |
37
|
|
|
|
|
|
|
# first element is assumed to be always a root node |
38
|
|
|
|
|
|
|
$node = $xml->getNode('rootnode'); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# xpath-like predicates are also supported so you can also do something like |
41
|
|
|
|
|
|
|
$node->addChildNode('child', 'value1'); |
42
|
|
|
|
|
|
|
$node->addChildNode('child', 'value2'); |
43
|
|
|
|
|
|
|
$child2 = $xml->getNode('/rootnode/child[2]'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# or even |
46
|
|
|
|
|
|
|
$node->addChildNode('child', 'value3', { attr => 'val' }); |
47
|
|
|
|
|
|
|
# the 3rd 'child' has an attribute |
48
|
|
|
|
|
|
|
$child3 = $xml->getNode('/rootnode/child[@attr="val"]'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#### IMPORTANT NOTE: #### |
51
|
|
|
|
|
|
|
# this is not xpath syntax. use XML::TinyXML::Selector::XPath |
52
|
|
|
|
|
|
|
# if you want to use an xpath-compliant syntax |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# see XML::TinyXML::Node documentation for further details on possible |
55
|
|
|
|
|
|
|
# operations on a node reference |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
######## ######### |
58
|
|
|
|
|
|
|
########## hashref2xml and xml2hashref facilities ########### |
59
|
|
|
|
|
|
|
######## ######### |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# An useful facility is loading/dumping of hashrefs from/to xml |
62
|
|
|
|
|
|
|
# for ex: |
63
|
|
|
|
|
|
|
$hashref = { some => 'thing', someother => 'thing' }; |
64
|
|
|
|
|
|
|
my $xml = XML::TinyXML->new($hashref, param => 'mystruct'); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# or to load on an existing XML::TinyXML object |
67
|
|
|
|
|
|
|
$xml->loadHash($hashref, 'mystruct'); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# we can also create and dump to string all at once : |
70
|
|
|
|
|
|
|
my $xmlstring = XML::TinyXML->new($hashref, param => 'mystruct')->dump; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# to reload the hashref back |
73
|
|
|
|
|
|
|
my $hashref = $xml->toHash; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DESCRIPTION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Since in some environments it could be desirable to avoid installing |
78
|
|
|
|
|
|
|
Expat, XmlParser and blahblahblah, needed by most XML-related perl modules, |
79
|
|
|
|
|
|
|
my main scope was to obtain a fast xml library usable from perl |
80
|
|
|
|
|
|
|
(so with the possibility to expose a powerful api) but without the need to install |
81
|
|
|
|
|
|
|
a lot of other modules (or even C libraries) to have it working. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The actual version of XML::TinyXML (0.18 when I'm writing this) |
84
|
|
|
|
|
|
|
implements an xpath selector and supports encodings (through iconv). |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The OO Tree-based api allows to : |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
- create a new document programmaticaly |
89
|
|
|
|
|
|
|
- import an existing document from a file |
90
|
|
|
|
|
|
|
- import an existing document by parsing a memory buffer |
91
|
|
|
|
|
|
|
- modify the loaded/created document programmatically |
92
|
|
|
|
|
|
|
- export the document to an xml file |
93
|
|
|
|
|
|
|
- bidirectional conversion between xml documents and perl hashrefs |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
There are other "no-dependencies" tiny xml implementations on CPAN. |
96
|
|
|
|
|
|
|
Notably : XML::Easy and XML::Tiny but both are still missing some key |
97
|
|
|
|
|
|
|
features which are actually implemented in this module and are required |
98
|
|
|
|
|
|
|
by the projects where I use it, in particular : |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
- an OO api to allow changing and re-exporting the xml document, |
101
|
|
|
|
|
|
|
- an easy-to-use bidirectional xml<->hashref conversion |
102
|
|
|
|
|
|
|
- encoding-conversion capabilities |
103
|
|
|
|
|
|
|
- xpath selectors |
104
|
|
|
|
|
|
|
- small memory footprint (well... it's always a perl module) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The underlying xml implementation resides in txml.c and is imported in the perl |
107
|
|
|
|
|
|
|
context through XS. It uses a linkedlist implementation took out of freebsd kernel |
108
|
|
|
|
|
|
|
and is supposed to be fast enough to represent and access 'not-huge' xml trees. |
109
|
|
|
|
|
|
|
If at some stage there will be need for more preformance in accessing the xml data |
110
|
|
|
|
|
|
|
(especially when using the xpath selector) an hash-table based index could be built |
111
|
|
|
|
|
|
|
on top of the tree structure to speed-up access to inner parts of the tree when using |
112
|
|
|
|
|
|
|
paths. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
An Event-based api is actually missing, but will be provided in future releases. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
package XML::TinyXML; |
123
|
|
|
|
|
|
|
|
124
|
10
|
|
|
10
|
|
255001
|
use strict; |
|
10
|
|
|
|
|
41
|
|
|
10
|
|
|
|
|
370
|
|
125
|
10
|
|
|
10
|
|
48
|
use warnings; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
286
|
|
126
|
10
|
|
|
10
|
|
51
|
use Carp; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
1105
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
require Exporter; |
129
|
10
|
|
|
10
|
|
9584
|
use AutoLoader; |
|
10
|
|
|
|
|
16655
|
|
|
10
|
|
|
|
|
55
|
|
130
|
|
|
|
|
|
|
|
131
|
10
|
|
|
10
|
|
10822
|
use XML::TinyXML::Node; |
|
10
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
3133
|
|
132
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
135
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
136
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# This allows declaration use XML::TinyXML ':all'; |
139
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
140
|
|
|
|
|
|
|
# will save memory. |
141
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
142
|
|
|
|
|
|
|
) ] ); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
our @EXPORT = qw( |
147
|
|
|
|
|
|
|
XML_BADARGS |
148
|
|
|
|
|
|
|
XML_GENERIC_ERR |
149
|
|
|
|
|
|
|
XML_LINKLIST_ERR |
150
|
|
|
|
|
|
|
XML_MEMORY_ERR |
151
|
|
|
|
|
|
|
XML_NOERR |
152
|
|
|
|
|
|
|
XML_OPEN_FILE_ERR |
153
|
|
|
|
|
|
|
XML_PARSER_GENERIC_ERR |
154
|
|
|
|
|
|
|
XML_MROOT_ERR |
155
|
|
|
|
|
|
|
XML_NODETYPE_SIMPLE |
156
|
|
|
|
|
|
|
XML_NODETYPE_COMMENT |
157
|
|
|
|
|
|
|
XML_NODETYPE_CDATA |
158
|
|
|
|
|
|
|
XML_BAD_CHARS |
159
|
|
|
|
|
|
|
XML_UPDATE_ERR |
160
|
|
|
|
|
|
|
XXmlAddAttribute |
161
|
|
|
|
|
|
|
XmlAddChildNode |
162
|
|
|
|
|
|
|
XmlAddRootNode |
163
|
|
|
|
|
|
|
XmlCountAttributes |
164
|
|
|
|
|
|
|
XmlCountBranches |
165
|
|
|
|
|
|
|
XmlCountChildren |
166
|
|
|
|
|
|
|
XmlCreateContext |
167
|
|
|
|
|
|
|
XmlDestroyContext |
168
|
|
|
|
|
|
|
XmlResetContext |
169
|
|
|
|
|
|
|
XmlCreateNode |
170
|
|
|
|
|
|
|
XmlDestroyNode |
171
|
|
|
|
|
|
|
XmlDump |
172
|
|
|
|
|
|
|
XmlDumpBranch |
173
|
|
|
|
|
|
|
XmlGetBranch |
174
|
|
|
|
|
|
|
XmlGetChildNode |
175
|
|
|
|
|
|
|
XmlGetChildNodeByName |
176
|
|
|
|
|
|
|
XmlGetNode |
177
|
|
|
|
|
|
|
XmlGetNodeValue |
178
|
|
|
|
|
|
|
XmlNextSibling |
179
|
|
|
|
|
|
|
XmlParseBuffer |
180
|
|
|
|
|
|
|
XmlParseFile |
181
|
|
|
|
|
|
|
XmlPrevSibling |
182
|
|
|
|
|
|
|
XmlRemoveBranch |
183
|
|
|
|
|
|
|
XmlRemoveChildNode |
184
|
|
|
|
|
|
|
XmlRemoveChildNodeAtIndex |
185
|
|
|
|
|
|
|
XmlRemoveNode |
186
|
|
|
|
|
|
|
XmlSave |
187
|
|
|
|
|
|
|
XmlSetNodeValue |
188
|
|
|
|
|
|
|
XmlSetOutputEncoding |
189
|
|
|
|
|
|
|
XmlSubstBranch |
190
|
|
|
|
|
|
|
XmlCreateNamespace |
191
|
|
|
|
|
|
|
XmlDestroyNamespace |
192
|
|
|
|
|
|
|
XmlGetNamespaceByName |
193
|
|
|
|
|
|
|
XmlGetNamespaceByUri |
194
|
|
|
|
|
|
|
XmlAddNamespace |
195
|
|
|
|
|
|
|
XmlGetNodeNamespace |
196
|
|
|
|
|
|
|
XmlSetNodeNamespace |
197
|
|
|
|
|
|
|
XmlSetNodeCNamespace |
198
|
|
|
|
|
|
|
XmlSetCurrentNamespace |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub AUTOLOAD { |
204
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
205
|
|
|
|
|
|
|
# XS function. |
206
|
|
|
|
|
|
|
|
207
|
17
|
|
|
17
|
|
719
|
my $constname; |
208
|
17
|
|
|
|
|
20
|
our $AUTOLOAD; |
209
|
17
|
|
|
|
|
82
|
($constname = $AUTOLOAD) =~ s/.*:://; |
210
|
17
|
50
|
|
|
|
53
|
croak "&XML::TinyXML::constant not defined" if $constname eq 'constant'; |
211
|
17
|
|
|
|
|
79
|
my ($error, $val) = constant($constname); |
212
|
17
|
50
|
|
|
|
37
|
if ($error) { croak $error; } |
|
0
|
|
|
|
|
0
|
|
213
|
|
|
|
|
|
|
{ |
214
|
10
|
|
|
10
|
|
104
|
no strict 'refs'; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
32127
|
|
|
17
|
|
|
|
|
21
|
|
215
|
|
|
|
|
|
|
# Fixed between 5.005_53 and 5.005_61 |
216
|
|
|
|
|
|
|
#XXX if ($] >= 5.00561) { |
217
|
|
|
|
|
|
|
#XXX *$AUTOLOAD = sub () { $val }; |
218
|
|
|
|
|
|
|
#XXX } |
219
|
|
|
|
|
|
|
#XXX else { |
220
|
17
|
|
|
211
|
|
335
|
*$AUTOLOAD = sub { $val }; |
|
211
|
|
|
|
|
783
|
|
221
|
|
|
|
|
|
|
#XXX } |
222
|
|
|
|
|
|
|
} |
223
|
17
|
|
|
|
|
65
|
goto &$AUTOLOAD; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
require XSLoader; |
227
|
|
|
|
|
|
|
XSLoader::load('XML::TinyXML', $VERSION); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# Preloaded methods go here. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * new ($arg, %params) |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Creates a new XML::TinyXML object. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
$root can be any of : |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
XML::TinyXML::Node |
238
|
|
|
|
|
|
|
XmlNodePtr |
239
|
|
|
|
|
|
|
HASHREF |
240
|
|
|
|
|
|
|
SCALAR |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
and if present will be used as first root node of the newly created |
243
|
|
|
|
|
|
|
xml document. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
%params is an optional hash parameter used only |
246
|
|
|
|
|
|
|
if $arg is an HASHREF or a scalar |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
%params = ( |
249
|
|
|
|
|
|
|
param => * if $root is an hashref, this will be |
250
|
|
|
|
|
|
|
name of the root node (it will be passed |
251
|
|
|
|
|
|
|
as second argument to loadHash()) |
252
|
|
|
|
|
|
|
* if $root is a scalar, this will be |
253
|
|
|
|
|
|
|
the value of the root node. |
254
|
|
|
|
|
|
|
attrs => attributes of the 'contextually added' $root node |
255
|
|
|
|
|
|
|
encoding => output encoding to use (among iconv supported ones) |
256
|
|
|
|
|
|
|
); |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub new { |
261
|
12
|
|
|
12
|
1
|
938
|
my ($class, $root, %params ) = @_; |
262
|
12
|
|
|
|
|
31
|
my $self = {} ; |
263
|
12
|
|
|
|
|
57
|
bless($self, $class); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# default encoding (the same used as default in the C library |
266
|
12
|
|
|
|
|
99
|
$self->{_encoding} = "utf-8"; |
267
|
12
|
|
|
|
|
358
|
$self->{_ctx} = XmlCreateContext(); |
268
|
12
|
50
|
|
|
|
54
|
$self->setOutputEncoding($params{encoding}) if ($params{encoding}); |
269
|
12
|
50
|
|
|
|
44
|
$self->allowMultipleRootNodes($params{multipleRootNodes}) if ($params{multipleRootNodes}); |
270
|
12
|
50
|
|
|
|
80
|
$self->ignoreBlanks($params{ignoreBlanks}) if (defined($params{ignoreBlanks})); |
271
|
12
|
50
|
|
|
|
48
|
$self->ignoreWhiteSpaces($params{ignoreWhiteSpaces}) if (defined($params{ignoreWhiteSpaces})); |
272
|
12
|
100
|
|
|
|
43
|
if($root) { |
273
|
1
|
50
|
0
|
|
|
12
|
if(UNIVERSAL::isa($root, "XML::TinyXML::Node")) { |
|
|
50
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
274
|
0
|
|
|
|
|
0
|
XmlAddRootNode($self->{_ctx}, $root->{_node}); |
275
|
|
|
|
|
|
|
} elsif(UNIVERSAL::isa($root, "XmlNodePtr")) { |
276
|
0
|
|
|
|
|
0
|
XmlAddRootNode($self->{_ctx}, $root); |
277
|
|
|
|
|
|
|
} elsif(ref($root) eq "HASH") { |
278
|
1
|
|
|
|
|
6
|
$self->loadHash($root, $params{param}); |
279
|
|
|
|
|
|
|
} elsif(defined($root) && (!ref($root) || ref($root) eq "SCALAR")) { |
280
|
0
|
|
|
|
|
0
|
$self->addRootNode($root, $params{param}, $params{attrs}); |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
12
|
|
|
|
|
45
|
return $self; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub open { |
288
|
0
|
|
|
0
|
0
|
0
|
my ($class, $file) = @_; |
289
|
0
|
|
|
|
|
0
|
my $self = $class->new(); |
290
|
0
|
0
|
|
|
|
0
|
return $self->loadFile($file) == $self->XML_NOERR |
291
|
|
|
|
|
|
|
? $self |
292
|
|
|
|
|
|
|
: undef; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item * addNodeAttribute ($node, $key, $value) |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Adds an attribute to a specific $node |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
$node MUST be an XML::TinyXML::Node object. |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
$key is the name of the attribute |
302
|
|
|
|
|
|
|
$value is the value of the attribute |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
This method is just an accessor. See XML::TinyXML::Node::addAttributes() instead. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
sub addNodeAttribute { |
309
|
0
|
|
|
0
|
1
|
0
|
my ($self, $node, $key, $value) = @_; |
310
|
0
|
0
|
0
|
|
|
0
|
return undef unless($node && UNIVERSAL::isa("XML::TinyXML::Node", $node)); |
311
|
0
|
|
|
|
|
0
|
return $node->addAttributes($key => $value); |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=item * removeNodeAttribute ($node, $index) |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Removes from $node the attribute at $index if present. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$node MUST be a XML::TinyXML::Node object. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
This method is just an accessor. See XML::TinyXML::Node::removeAttribute() instead. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=cut |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
sub removeNodeAttribute { |
325
|
0
|
|
|
0
|
1
|
0
|
my ($self, $node, $index) = @_; |
326
|
0
|
0
|
0
|
|
|
0
|
return undef unless($node && UNIVERSAL::isa("XML::TinyXML::Node", $node)); |
327
|
0
|
|
|
|
|
0
|
return $node->removeAttribute($index); |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=item * addRootNode ($name, $val, $attrs) |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
Adds a new root node. |
333
|
|
|
|
|
|
|
(This can be considered both as a new tree in the forest represented in the xml document |
334
|
|
|
|
|
|
|
or as a new branch in the xml tree represented by the document itself) |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=cut |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
sub addRootNode { |
339
|
5
|
|
|
5
|
1
|
13
|
my ($self, $name, $val, $attrs) = @_; |
340
|
|
|
|
|
|
|
|
341
|
5
|
100
|
|
|
|
19
|
$val = "" |
342
|
|
|
|
|
|
|
unless(defined($val)); |
343
|
|
|
|
|
|
|
|
344
|
5
|
50
|
66
|
|
|
26
|
return $self->XML_BADARGS |
345
|
|
|
|
|
|
|
if($attrs && ref($attrs) ne "HASH"); |
346
|
|
|
|
|
|
|
|
347
|
5
|
|
|
|
|
30
|
my $node = XML::TinyXML::Node->new($name, $val, $attrs); |
348
|
|
|
|
|
|
|
|
349
|
5
|
50
|
|
|
|
16
|
return $self->XML_GENERIC_ERR |
350
|
|
|
|
|
|
|
unless($node); |
351
|
|
|
|
|
|
|
|
352
|
5
|
|
|
|
|
86
|
return XmlAddRootNode($self->{_ctx}, $node->{_node}); |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=item * addChildNode ($parent, $name, $val, $attrs) |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
Adds a new child node. |
358
|
|
|
|
|
|
|
This method is exactly like addRootNode but first argument must be a valid XML::TinyXML::Node |
359
|
|
|
|
|
|
|
which will be the parent of the newly created node |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=cut |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
sub addChildNode { |
364
|
0
|
|
|
0
|
1
|
0
|
my ($self, $node, $name, $val, $attrs) = @_; |
365
|
|
|
|
|
|
|
|
366
|
0
|
0
|
0
|
|
|
0
|
return $self->XML_BADARGS |
367
|
|
|
|
|
|
|
unless (ref($node) && UNIVERSAL::isa("XML::TinyXML::Node", $node)); |
368
|
|
|
|
|
|
|
|
369
|
0
|
0
|
0
|
|
|
0
|
return $self->XML_BADARGS |
370
|
|
|
|
|
|
|
if($attrs && ref($attrs) ne "HASH"); |
371
|
|
|
|
|
|
|
|
372
|
0
|
0
|
|
|
|
0
|
$val = "" |
373
|
|
|
|
|
|
|
unless(defined($val)); |
374
|
|
|
|
|
|
|
|
375
|
0
|
|
|
|
|
0
|
my $child = XML::TinyXML::Node->new($name, $val, $attrs, $node); |
376
|
|
|
|
|
|
|
|
377
|
0
|
0
|
|
|
|
0
|
return $self->XML_GENERIC_ERR |
378
|
|
|
|
|
|
|
unless($child); |
379
|
|
|
|
|
|
|
|
380
|
0
|
|
|
|
|
0
|
return XmlAddChildNode($self->{_ctx}, $node->{_node}); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
=item * dump () |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
Returns a stringified version of the XML structure represented internally |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=cut |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
sub dump { |
390
|
3
|
|
|
3
|
1
|
78
|
my $self = shift; |
391
|
3
|
|
|
|
|
128
|
return XmlDump($self->{_ctx}); |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=item * loadFile ($path) |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
Load the xml structure from a file |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=cut |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub loadFile { |
401
|
10
|
|
|
10
|
1
|
53
|
my ($self, $path) = @_; |
402
|
10
|
|
|
|
|
1947
|
return XmlParseFile($self->{_ctx}, $path); |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=item * loadHash ($hash, $root) |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
Load the xml structure from an hashref (AKA: convert an hashref to an xml document) |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
if $root is specified, it will be the entity name of the root node |
410
|
|
|
|
|
|
|
in the resulting xml document. |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=cut |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
sub loadHash { |
415
|
1
|
|
|
1
|
1
|
4
|
my ($self, $hash, $root) = @_; |
416
|
1
|
50
|
|
|
|
3
|
$root = "txml" |
417
|
|
|
|
|
|
|
unless($root); |
418
|
|
|
|
|
|
|
|
419
|
1
|
|
|
|
|
2
|
my $cur = undef; |
420
|
1
|
50
|
33
|
|
|
6
|
if(ref($root) && UNIVERSAL::isa("XML::TinyXML::Node", $root)) { |
421
|
0
|
|
|
|
|
0
|
XmlAddRootNode($self->{_ctx}, $root->{_node}); |
422
|
0
|
|
|
|
|
0
|
$cur = $root; |
423
|
|
|
|
|
|
|
} else { |
424
|
1
|
|
|
|
|
3
|
$self->addRootNode($root); |
425
|
1
|
50
|
|
|
|
4
|
$cur = $self->allowMultipleRootNodes |
426
|
|
|
|
|
|
|
? $self->getNode($root) |
427
|
|
|
|
|
|
|
: $self->getRootNode(0); |
428
|
|
|
|
|
|
|
} |
429
|
1
|
|
|
|
|
5
|
return $cur->loadHash($hash); |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=item * toHash () |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
Dump the xml structure represented internally in the form of an hashref |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
=cut |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
sub toHash { |
439
|
1
|
|
|
1
|
1
|
756
|
my ($self) = shift; |
440
|
|
|
|
|
|
|
# only first branch will be parsed ... This means that if multiple root |
441
|
|
|
|
|
|
|
# nodes are present (which is anyway not allowed by the xml spec), only |
442
|
|
|
|
|
|
|
# the first one will be parsed and translated into an hashref |
443
|
1
|
|
|
|
|
4
|
my $node = $self->getRootNode(0); |
444
|
1
|
|
|
|
|
14
|
return $node->toHash; |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=item * loadBuffer ($buf) |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
Load the xml structure from a preloaded memory buffer |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=cut |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
sub loadBuffer { |
454
|
1
|
|
|
1
|
1
|
8
|
my ($self, $buf) = @_; |
455
|
1
|
|
|
|
|
70
|
return XmlParseBuffer($self->{_ctx}, $buf); |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=item * getNode ($path) |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
Get a node at a specific path. |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
$path must be of the form: '/rootnode/child1/child2/leafnod' |
463
|
|
|
|
|
|
|
and the leading '/' is optional (since all paths will be interpreted |
464
|
|
|
|
|
|
|
as absolute) |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
Returns an XML::TinyXML::Node object |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=cut |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
sub getNode { |
471
|
18
|
|
|
18
|
1
|
106
|
my ($self, $path) = @_; |
472
|
18
|
|
|
|
|
215
|
return XML::TinyXML::Node->new(XmlGetNode($self->{_ctx}, $path)); |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=item * getChildNode ($node, $index) |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
Get the child of $node at index $index. |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
Returns an XML::TinyXML::Node object |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
=cut |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
sub getChildNode { |
484
|
0
|
|
|
0
|
1
|
0
|
my ($self, $node, $index) = @_; |
485
|
0
|
|
|
|
|
0
|
return XML::TinyXML::Node->new(XmlGetChildNode($node, $index)); |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=item * countChildren () |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
Returns the number of $node's children |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=cut |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
sub countChildren { |
495
|
3
|
|
|
3
|
1
|
12
|
my ($self, $node) = @_; |
496
|
3
|
100
|
|
|
|
27
|
if(UNIVERSAL::isa($node, "XML::TinyXML::Node")) { |
|
|
100
|
|
|
|
|
|
497
|
1
|
|
|
|
|
8
|
return XmlCountChildren($node->{_node}); |
498
|
|
|
|
|
|
|
} elsif(UNIVERSAL::isa($node, "XmlNodePtr")) { |
499
|
1
|
|
|
|
|
8
|
return XmlCountChildren($node); |
500
|
|
|
|
|
|
|
} else { |
501
|
|
|
|
|
|
|
# assume we have been provided a path |
502
|
1
|
|
|
|
|
15
|
my $node = XmlGetNode($self->{_ctx}, $node); |
503
|
1
|
50
|
|
|
|
24
|
return XmlCountChildren($node) |
504
|
|
|
|
|
|
|
if ($node); |
505
|
|
|
|
|
|
|
} |
506
|
0
|
|
|
|
|
0
|
return undef; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
=item * removeNode ($path) |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
Remove the node at specific $path, if present. |
512
|
|
|
|
|
|
|
See getNode() documentation for some notes on the $path format. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
Returns XML_NOERR (0) if success, error code otherwise. |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
See Exportable constants for a list of possible error codes |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=cut |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
sub removeNode { |
521
|
0
|
|
|
0
|
1
|
0
|
my ($self, $path) = @_; |
522
|
0
|
|
|
|
|
0
|
return XmlRemoveNode($self->{_ctx}, $path); |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=item * getBranch ($index) |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
alias for getRootNode |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=cut |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
sub getBranch { |
532
|
3
|
|
|
3
|
1
|
5
|
my ($self, $index) = @_; |
533
|
3
|
|
|
|
|
44
|
return XML::TinyXML::Node->new(XmlGetBranch($self->{_ctx}, $index)); |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=item * getRootNode ($index) |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
Get the root node at $index. |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
Returns an XML::TinyXML::Node object if present, undef otherwise |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=cut |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
sub getRootNode { |
545
|
3
|
|
|
3
|
1
|
9
|
my ($self, $index) = @_; |
546
|
3
|
|
|
|
|
11
|
return $self->getBranch($index); |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=item * removeBranch ($index) |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
Alias for removeRootNode |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=cut |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
sub removeBranch { |
556
|
1
|
|
|
1
|
1
|
3
|
my ($self, $index) = @_; |
557
|
1
|
|
|
|
|
19
|
return XmlRemoveBranch($self->{_ctx}, $index); |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=item * removeRootNode ($index) |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
Remove the rootnode (and all his children) at $index. |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=cut |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
sub removeRootNode { |
567
|
1
|
|
|
1
|
1
|
921
|
my ($self, $index) = @_; |
568
|
1
|
|
|
|
|
4
|
return $self->removeBranch($index); |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=item * countRootNodes |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
Returns the number of root nodes within this context |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=cut |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub countRootNodes { |
578
|
4
|
|
|
4
|
1
|
13
|
my ($self) = @_; |
579
|
4
|
|
|
|
|
24
|
return XmlCountBranches($self->{_ctx}); |
580
|
|
|
|
|
|
|
} |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=item * rootNodes () |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
Returns an array containing all rootnodes. |
585
|
|
|
|
|
|
|
In scalar context returns an arrayref. |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=cut |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
sub rootNodes { |
590
|
143
|
|
|
143
|
1
|
653
|
my ($self) = @_; |
591
|
143
|
|
|
|
|
154
|
my @nodes; |
592
|
143
|
|
|
|
|
755
|
for (my $i = 0; $i < XmlCountBranches($self->{_ctx}); $i++) { |
593
|
144
|
|
|
|
|
806
|
push (@nodes, XML::TinyXML::Node->new(XmlGetBranch($self->{_ctx}, $i))); |
594
|
|
|
|
|
|
|
} |
595
|
143
|
100
|
|
|
|
768
|
return wantarray?@nodes:\@nodes; |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=item * getChildNodeByName ($node, $name) |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
Get the child of $node with name == $name. |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
Returns an XML::TinyXML::Node object if there is such a child, undef otherwise |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
=cut |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
sub getChildNodeByName { |
607
|
0
|
|
|
0
|
1
|
0
|
my ($self, $node, $name) = @_; |
608
|
0
|
0
|
|
|
|
0
|
if ($node) { |
609
|
0
|
|
|
|
|
0
|
return XML::TinyXML::Node->new(XmlGetChildNodeByName($node, $name)); |
610
|
|
|
|
|
|
|
} else { |
611
|
0
|
|
|
|
|
0
|
my $count = XmlCountBranches($self->{_ctx}); |
612
|
0
|
|
|
|
|
0
|
for (my $i = 0 ; $i < $count; $i++ ){ |
613
|
0
|
|
|
|
|
0
|
my $res = XmlGetChildNodeByName(XmlGetBranch($self->{_ctx}, $i), $name); |
614
|
0
|
0
|
|
|
|
0
|
return XML::TinyXML::Node->new($res) if($res); |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
} |
618
|
0
|
|
|
|
|
0
|
return undef; |
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
sub cNode { |
622
|
0
|
|
|
0
|
0
|
0
|
my ($self, $value) = @_; |
623
|
0
|
0
|
|
|
|
0
|
return $value |
624
|
|
|
|
|
|
|
? $self->{_ctx}->cNode($value) |
625
|
|
|
|
|
|
|
: $self->{_ctx}->cNode; |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=item * save ($path) |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
Save the xml document represented internally into $path. |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
Returns XML_NOERR if success, a specific error code otherwise |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=cut |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
sub save { |
637
|
0
|
|
|
0
|
1
|
0
|
my ($self, $path) = @_; |
638
|
0
|
|
|
|
|
0
|
return XmlSave($self->{_ctx}, $path); |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item * setOutputEncoding ($encoding) |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
Sets the output encding to the specified one |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
(any iconv-supported encoding is a valid argument for this method) |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
Returns XML_NOERR if success, a specific error code otherwise |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
=cut |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub setOutputEncoding { |
652
|
0
|
|
|
0
|
1
|
0
|
my ($self, $encoding) = @_; |
653
|
0
|
|
|
|
|
0
|
$self->{_encoding} = $encoding; |
654
|
0
|
|
|
|
|
0
|
XmlSetOutputEncoding($self->{_ctx}, $encoding); |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=item * allowMultipleRootNodes ($bool) |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
Allow to control if the document can contain multiple root nodes (out of xml spec) |
660
|
|
|
|
|
|
|
or if it will support only one single root node. Default is 0 |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=cut |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
sub allowMultipleRootNodes { |
665
|
183
|
|
|
183
|
1
|
259
|
my ($self, $val) = @_; |
666
|
183
|
100
|
|
|
|
879
|
return defined($val) |
667
|
|
|
|
|
|
|
? $self->{_ctx}->allowMultipleRootNodes($val) |
668
|
|
|
|
|
|
|
: $self->{_ctx}->allowMultipleRootNodes; |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=item * ignoreBlanks ($bool) |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
Controls the behaviour of both the parser and the dumper. |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
- Parser : |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
If ignoreBlanks is true any 'tab', 'newline' and 'carriage-return' ("\t", "\n", "\r"), |
678
|
|
|
|
|
|
|
between two tags will be ignored, unless surrounded by non-whitespace character. |
679
|
|
|
|
|
|
|
For example, considering the following node: |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
value |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
( literally : "\n\tvalue\n" ) |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
the parser will ignore the newlines and the tab between two nodes. |
688
|
|
|
|
|
|
|
So, the resulting structure would be : |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
$node = { |
691
|
|
|
|
|
|
|
value => undef, |
692
|
|
|
|
|
|
|
children => [ { child => "value" } ] |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
If ignoreBlanks is false, all characters between the node tags will be part of the |
696
|
|
|
|
|
|
|
value and the result would be : |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
$node = { |
699
|
|
|
|
|
|
|
value => "\n\t\n", |
700
|
|
|
|
|
|
|
children => [ { child => "value" } ] |
701
|
|
|
|
|
|
|
} |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
- Dumper : |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
If ignoreBlanks is true, both newlines and tabs will be used to prettify text formatting, |
706
|
|
|
|
|
|
|
so the node in the previous example will be printed out as: |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
value |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
If ignoreBlanks is false, no extra characters will be added to the xml data |
713
|
|
|
|
|
|
|
(so no newlines, indentation or such). |
714
|
|
|
|
|
|
|
The previous example would be dumped as follows: |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
value |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
Default is 1. |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
=cut |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
sub ignoreBlanks { |
723
|
2
|
|
|
2
|
1
|
1280
|
my ($self, $val) = @_; |
724
|
2
|
50
|
|
|
|
21
|
return defined($val) |
725
|
|
|
|
|
|
|
? $self->{_ctx}->ignoreBlanks($val) |
726
|
|
|
|
|
|
|
: $self->{_ctx}->ignoreBlanks; |
727
|
|
|
|
|
|
|
} |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=item * ignoreWhiteSpaces ($bool) |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
Controls the behaviour of the parser. |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
This flag includes the literal whitespace ' ' among the ignored characters |
734
|
|
|
|
|
|
|
commended by ignoreBlanks() |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
consider the following examples: |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
- if true: |
741
|
|
|
|
|
|
|
value = "" |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
- if false: |
744
|
|
|
|
|
|
|
value = " " |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
The parser will ignore the whitespace if this flag is true. |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
a value |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
a value |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
a value |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
- if true: |
755
|
|
|
|
|
|
|
value = "a value" |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
- if false: |
758
|
|
|
|
|
|
|
value = " a value " |
759
|
|
|
|
|
|
|
" a value" |
760
|
|
|
|
|
|
|
"a value " |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
The whitespace will be part of the value if this flag is false. |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
The dumper is not affected by this flag. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
Default is 1 |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=cut |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
sub ignoreWhiteSpaces { |
771
|
2
|
|
|
2
|
1
|
10
|
my ($self, $val) = @_; |
772
|
2
|
50
|
|
|
|
15
|
return defined($val) |
773
|
|
|
|
|
|
|
? $self->{_ctx}->ignoreWhiteSpaces($val) |
774
|
|
|
|
|
|
|
: $self->{_ctx}->ignoreWhiteSpaces; |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
sub hasIconv { |
778
|
1
|
|
|
1
|
0
|
5
|
my $self = shift; |
779
|
1
|
|
|
|
|
4
|
return $self->{_ctx}->hasIconv; |
780
|
|
|
|
|
|
|
} |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
sub DESTROY { |
783
|
11
|
|
|
11
|
|
7289
|
my $self = shift; |
784
|
11
|
50
|
|
|
|
1953
|
XmlDestroyContext($self->{_ctx}) |
785
|
|
|
|
|
|
|
if($self->{_ctx}); |
786
|
|
|
|
|
|
|
} |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
1; |
791
|
|
|
|
|
|
|
__END__ |