line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::WriteExcelXML::XMLwriter; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# XMLwriter - A base class for Excel workbooks and worksheets. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Used in conjunction with Spreadsheet::WriteExcelXML |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Documentation after __END__ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
24
|
|
|
24
|
|
690
|
use Exporter; |
|
24
|
|
|
|
|
61
|
|
|
24
|
|
|
|
|
1010
|
|
16
|
24
|
|
|
24
|
|
130
|
use strict; |
|
24
|
|
|
|
|
76
|
|
|
24
|
|
|
|
|
655
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
24
|
|
|
24
|
|
123
|
use vars qw($VERSION @ISA); |
|
24
|
|
|
|
|
53
|
|
|
24
|
|
|
|
|
22901
|
|
26
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$VERSION = '0.15'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# new() |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# Constructor |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
sub new { |
37
|
|
|
|
|
|
|
|
38
|
101
|
|
|
101
|
0
|
507
|
my $class = $_[0]; |
39
|
|
|
|
|
|
|
|
40
|
101
|
|
|
|
|
384
|
my $self = { |
41
|
|
|
|
|
|
|
_filehandle => $_[1], |
42
|
|
|
|
|
|
|
_indentation => " ", |
43
|
|
|
|
|
|
|
_no_encoding => 0, |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
101
|
|
|
|
|
219
|
bless $self, $class; |
47
|
101
|
|
|
|
|
246
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
############################################################################### |
52
|
|
|
|
|
|
|
# |
53
|
|
|
|
|
|
|
# _format_tag($level, $nl, $list, @attributes) |
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
# This function formats an XML element tag for printing. Adds indentation and |
56
|
|
|
|
|
|
|
# newlines as specified. Keeps attributes, if any, on one line or formats |
57
|
|
|
|
|
|
|
# them one per line. |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# Args: |
60
|
|
|
|
|
|
|
# $level = The indentation level (int) |
61
|
|
|
|
|
|
|
# $nl = Number of newlines after tag (int) |
62
|
|
|
|
|
|
|
# $list = List attributes on separate lines (0, 1, 2) |
63
|
|
|
|
|
|
|
# 0 = No list |
64
|
|
|
|
|
|
|
# 1 = Automatic list |
65
|
|
|
|
|
|
|
# 2 = Explicit list |
66
|
|
|
|
|
|
|
# @attributes = Attribute/Value pairs |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
# The list option puts the attributes on separate lines if there is more |
69
|
|
|
|
|
|
|
# than one attribute. List option 2 generates this effect even when there |
70
|
|
|
|
|
|
|
# is only one attribute. |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
sub _format_tag { |
73
|
|
|
|
|
|
|
|
74
|
2244
|
|
|
2244
|
|
3309
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
2244
|
|
|
|
|
3220
|
my $level = shift; |
77
|
2244
|
|
|
|
|
3342
|
my $nl = shift; |
78
|
2244
|
|
|
|
|
3108
|
my $list = shift; |
79
|
|
|
|
|
|
|
|
80
|
2244
|
|
|
|
|
5177
|
my $element = $self->{_indentation} x $level. '<' . shift; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Autolist option. Only use list format if there is more than 1 attribute. |
83
|
2244
|
100
|
100
|
|
|
5129
|
$list = 0 if $list == 1 and @_ <= 2; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Special case. If _indentation is "" avoid all unnecessary whitespace |
87
|
2244
|
100
|
|
|
|
4478
|
$list = 0 if $self->{_indentation} eq ""; |
88
|
2244
|
100
|
|
|
|
4149
|
$nl = 0 if $self->{_indentation} eq ""; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
2244
|
|
|
|
|
4303
|
while (@_) { |
92
|
1334
|
|
|
|
|
2049
|
my $attrib = shift; |
93
|
1334
|
|
|
|
|
2576
|
my $value = $self->_encode_xml_escapes(shift); |
94
|
|
|
|
|
|
|
|
95
|
1334
|
100
|
|
|
|
2607
|
if ($list) {$element .= "\n" . $self->{_indentation} x ($level +1);} |
|
96
|
|
|
|
|
236
|
|
96
|
1238
|
|
|
|
|
1887
|
else {$element .= ' '; } |
97
|
|
|
|
|
|
|
|
98
|
1334
|
|
|
|
|
1973
|
$element .= $attrib; |
99
|
1334
|
|
|
|
|
3342
|
$element .= '="' . $value . '"'; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
2244
|
100
|
|
|
|
4400
|
$nl = $nl ? "\n" x $nl : ""; |
103
|
|
|
|
|
|
|
|
104
|
2244
|
|
|
|
|
5346
|
return $element . '>'. $nl; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################################### |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# _encode_xml_escapes() |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# Encode standard XML escapes, namely " & < > and \n. The apostrophe character |
113
|
|
|
|
|
|
|
# isn't escaped since it will only occur in double quoted strings. |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
sub _encode_xml_escapes { |
116
|
|
|
|
|
|
|
|
117
|
1546
|
|
|
1546
|
|
6571
|
my $self = shift; |
118
|
1546
|
|
|
|
|
2408
|
my $value = $_[0]; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Print un-encoded entities for debugging |
121
|
1546
|
50
|
|
|
|
3091
|
return $value if $self->{_no_encoding}; |
122
|
|
|
|
|
|
|
|
123
|
1546
|
|
|
|
|
2757
|
for ($value) { |
124
|
1546
|
|
|
|
|
3140
|
s/&/&/g; |
125
|
1546
|
|
|
|
|
2329
|
s/</g; |
126
|
1546
|
|
|
|
|
2338
|
s/>/>/g; |
127
|
1546
|
|
|
|
|
2299
|
s/"/"/g; # " |
128
|
|
|
|
|
|
|
#s/'/&pos;/g; # Not used |
129
|
1546
|
|
|
|
|
2667
|
s/\n/
/g; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
1546
|
|
|
|
|
3320
|
return $value; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
############################################################################### |
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
# _write_xml_start_tag() |
139
|
|
|
|
|
|
|
# |
140
|
|
|
|
|
|
|
# Creates a formatted XML opening tag. Prints to the current filehandle by |
141
|
|
|
|
|
|
|
# default. |
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# Ex: |
144
|
|
|
|
|
|
|
# |
145
|
|
|
|
|
|
|
sub _write_xml_start_tag { |
146
|
|
|
|
|
|
|
|
147
|
958
|
|
|
958
|
|
8825
|
my $self = shift; |
148
|
|
|
|
|
|
|
|
149
|
958
|
|
|
|
|
2070
|
my $tag = $self->_format_tag(@_); |
150
|
|
|
|
|
|
|
|
151
|
958
|
|
|
|
|
2370
|
local $\; # Make print() ignore -l on the command line. |
152
|
958
|
100
|
|
|
|
2093
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
929
|
|
|
|
|
2520
|
|
153
|
|
|
|
|
|
|
|
154
|
958
|
|
|
|
|
2432
|
return $tag; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
############################################################################### |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# _write_xml_directive() |
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
# Creates a formatted XML ?> directive. Prints to the current filehandle by |
163
|
|
|
|
|
|
|
# default. |
164
|
|
|
|
|
|
|
# |
165
|
|
|
|
|
|
|
# Ex: |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
sub _write_xml_directive { |
168
|
|
|
|
|
|
|
|
169
|
40
|
|
|
40
|
|
2375
|
my $self = shift; |
170
|
|
|
|
|
|
|
|
171
|
40
|
|
|
|
|
219
|
my $tag = $self->_format_tag(@_); |
172
|
40
|
|
|
|
|
171
|
$tag =~ s[<][]; |
173
|
40
|
|
|
|
|
133
|
$tag =~ s[>][?>]; |
174
|
|
|
|
|
|
|
|
175
|
40
|
|
|
|
|
170
|
local $\; # Make print() ignore -l on the command line. |
176
|
40
|
100
|
|
|
|
163
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
36
|
|
|
|
|
426
|
|
177
|
|
|
|
|
|
|
|
178
|
40
|
|
|
|
|
162
|
return $tag; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
############################################################################### |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
# _write_xml_end_tag() |
185
|
|
|
|
|
|
|
# |
186
|
|
|
|
|
|
|
# Creates the closing tag of an XML element. Prints to the current filehandle |
187
|
|
|
|
|
|
|
# by default. |
188
|
|
|
|
|
|
|
# |
189
|
|
|
|
|
|
|
# Ex: |
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
sub _write_xml_end_tag { |
192
|
|
|
|
|
|
|
|
193
|
932
|
|
|
932
|
|
3137
|
my $self = shift; |
194
|
|
|
|
|
|
|
|
195
|
932
|
|
|
|
|
1790
|
my $tag = $self->_format_tag(@_); |
196
|
932
|
|
|
|
|
2774
|
$tag =~ s[<][]; |
197
|
|
|
|
|
|
|
|
198
|
932
|
|
|
|
|
2167
|
local $\; # Make print() ignore -l on the command line. |
199
|
932
|
100
|
|
|
|
2040
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
929
|
|
|
|
|
2043
|
|
200
|
|
|
|
|
|
|
|
201
|
932
|
|
|
|
|
2582
|
return $tag; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
############################################################################### |
207
|
|
|
|
|
|
|
# |
208
|
|
|
|
|
|
|
# _write_xml_element() |
209
|
|
|
|
|
|
|
# |
210
|
|
|
|
|
|
|
# Creates a single open and closed XML element. Prints to the current |
211
|
|
|
|
|
|
|
# filehandle by default. |
212
|
|
|
|
|
|
|
# |
213
|
|
|
|
|
|
|
# Ex: or |
214
|
|
|
|
|
|
|
# |
215
|
|
|
|
|
|
|
sub _write_xml_element { |
216
|
|
|
|
|
|
|
|
217
|
314
|
|
|
314
|
|
2746
|
my $self = shift; |
218
|
|
|
|
|
|
|
|
219
|
314
|
|
|
|
|
826
|
my $tag = $self->_format_tag(@_); |
220
|
314
|
|
|
|
|
1093
|
$tag =~ s[>][/>]; |
221
|
|
|
|
|
|
|
|
222
|
314
|
|
|
|
|
962
|
local $\; # Make print() ignore -l on the command line. |
223
|
314
|
100
|
|
|
|
757
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
140
|
|
|
|
|
413
|
|
224
|
|
|
|
|
|
|
|
225
|
314
|
|
|
|
|
1407
|
return $tag; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
############################################################################### |
230
|
|
|
|
|
|
|
# |
231
|
|
|
|
|
|
|
# _write_xml_content() |
232
|
|
|
|
|
|
|
# |
233
|
|
|
|
|
|
|
# Creates an encoded XML element content. Prints to the current filehandle |
234
|
|
|
|
|
|
|
# by default. |
235
|
|
|
|
|
|
|
# |
236
|
|
|
|
|
|
|
# Ex: Hello in Hello |
237
|
|
|
|
|
|
|
# |
238
|
|
|
|
|
|
|
sub _write_xml_content { |
239
|
|
|
|
|
|
|
|
240
|
204
|
|
|
204
|
|
1372
|
my $self = shift; |
241
|
|
|
|
|
|
|
|
242
|
204
|
|
|
|
|
425
|
my $tag = $self->_encode_xml_escapes($_[0]); |
243
|
|
|
|
|
|
|
|
244
|
204
|
|
|
|
|
463
|
local $\; # Make print() ignore -l on the command line. |
245
|
204
|
100
|
|
|
|
483
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
202
|
|
|
|
|
432
|
|
246
|
|
|
|
|
|
|
|
247
|
204
|
|
|
|
|
529
|
return $tag; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
############################################################################### |
253
|
|
|
|
|
|
|
# |
254
|
|
|
|
|
|
|
# _write_xml_unencoded_content() |
255
|
|
|
|
|
|
|
# |
256
|
|
|
|
|
|
|
# Creates an un-encoded XML element content. Prints to the current filehandle |
257
|
|
|
|
|
|
|
# by default. Used for numerical or other data that doesn't need to be |
258
|
|
|
|
|
|
|
# encoded. |
259
|
|
|
|
|
|
|
# |
260
|
|
|
|
|
|
|
# Ex: 1.2345 in 1.2345 |
261
|
|
|
|
|
|
|
# |
262
|
|
|
|
|
|
|
sub _write_xml_unencoded_content { |
263
|
|
|
|
|
|
|
|
264
|
55
|
|
|
55
|
|
1693
|
my $self = shift; |
265
|
|
|
|
|
|
|
|
266
|
55
|
|
|
|
|
110
|
my $tag = $_[0]; |
267
|
|
|
|
|
|
|
|
268
|
55
|
|
|
|
|
123
|
local $\; # Make print() ignore -l on the command line. |
269
|
55
|
100
|
|
|
|
166
|
print {$self->{_filehandle}} $tag if $self->{_filehandle}; |
|
52
|
|
|
|
|
174
|
|
270
|
|
|
|
|
|
|
|
271
|
55
|
|
|
|
|
166
|
return $tag; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
############################################################################### |
276
|
|
|
|
|
|
|
# |
277
|
|
|
|
|
|
|
# set_indentation() |
278
|
|
|
|
|
|
|
# |
279
|
|
|
|
|
|
|
# Set indentation string used to indent the output. The default is 4 spaces. |
280
|
|
|
|
|
|
|
# |
281
|
|
|
|
|
|
|
sub set_indentation { |
282
|
|
|
|
|
|
|
|
283
|
16
|
|
|
16
|
1
|
8694
|
my $self = shift; |
284
|
16
|
100
|
|
|
|
58
|
$self->{_indentation} = defined $_[0] ? $_[0] : ' '; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
1; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
__END__ |