line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: XML.pm 456 2009-04-15 12:20:59Z fil $ |
2
|
|
|
|
|
|
|
package Data::Tabular::Dumper::XML; |
3
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
118
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
3793
|
use Data::Tabular::Dumper::Writer; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
120
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
20
|
use vars qw( @ISA ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2767
|
|
8
|
|
|
|
|
|
|
@ISA = qw( Data::Tabular::Dumper::Writer ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
########################################################### |
11
|
|
|
|
|
|
|
sub open |
12
|
|
|
|
|
|
|
{ |
13
|
13
|
|
|
13
|
0
|
26
|
my($package, $param)=@_; |
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
44
|
my($file, $top, $record)=@$param; |
16
|
13
|
|
|
|
|
101
|
my $self = $package->SUPER::open( $file ); |
17
|
|
|
|
|
|
|
|
18
|
13
|
|
50
|
|
|
47
|
$top||='DATA'; |
19
|
13
|
|
100
|
|
|
47
|
$record||='RECORD'; |
20
|
|
|
|
|
|
|
|
21
|
13
|
|
|
|
|
51
|
my $fh = $self->{fh}; |
22
|
13
|
|
|
|
|
281
|
print $fh qq(\n<$top>\n); |
23
|
|
|
|
|
|
|
|
24
|
13
|
|
|
|
|
44
|
$self->{top} = $top; |
25
|
13
|
|
|
|
|
30
|
$self->{record} = $record; |
26
|
13
|
|
|
|
|
34
|
$self->{prefix} = ''; |
27
|
|
|
|
|
|
|
|
28
|
13
|
|
|
|
|
49
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
########################################################### |
32
|
|
|
|
|
|
|
sub close |
33
|
|
|
|
|
|
|
{ |
34
|
26
|
|
|
26
|
0
|
44
|
my($self)=@_; |
35
|
26
|
|
|
|
|
87
|
my $fh = delete $self->{fh}; |
36
|
26
|
100
|
|
|
|
98
|
return unless $fh; |
37
|
13
|
|
|
|
|
872
|
print $fh qq($self->{top}>\n) ; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
########################################################### |
41
|
|
|
|
|
|
|
sub fields |
42
|
|
|
|
|
|
|
{ |
43
|
11
|
|
|
11
|
0
|
18
|
my($self, $fields)=@_; |
44
|
11
|
|
|
|
|
53
|
$self->{fields}=[@$fields]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
########################################################### |
48
|
|
|
|
|
|
|
sub write |
49
|
|
|
|
|
|
|
{ |
50
|
37
|
|
|
37
|
0
|
58
|
my($self, $data)=@_; |
51
|
|
|
|
|
|
|
|
52
|
37
|
|
|
|
|
96
|
my $fh=$self->{fh}; |
53
|
|
|
|
|
|
|
|
54
|
37
|
|
|
|
|
55
|
my $record = $self->{record}; |
55
|
37
|
|
|
|
|
43
|
my $q = 0; |
56
|
37
|
100
|
100
|
|
|
68
|
if( 1 < @{$self->{fields}} and $self->{fields}[0] eq '' |
|
37
|
|
66
|
|
|
249
|
|
57
|
|
|
|
|
|
|
and $data->[0] ne '' ) { |
58
|
6
|
|
|
|
|
10
|
$record = $data->[0]; |
59
|
6
|
|
|
|
|
7
|
$q++; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
37
|
|
|
|
|
121
|
print $fh qq($self->{prefix} <$record>\n); |
63
|
37
|
|
|
|
|
114
|
for( ; $q <=$#$data ; $q++ ) { |
64
|
132
|
100
|
|
|
|
192
|
my $f = $self->{fields}[$q > $#{$self->{fields}} ? -1 : $q]; |
|
132
|
|
|
|
|
354
|
|
65
|
132
|
100
|
66
|
|
|
480
|
$f = $q if not defined $f or $f eq ''; |
66
|
132
|
|
|
|
|
185
|
my $d=$data->[$q]; |
67
|
132
|
100
|
|
|
|
385
|
next unless defined $d; |
68
|
100
|
|
|
|
|
185
|
$d=~s/&/&/g; |
69
|
100
|
|
|
|
|
120
|
$d=~s/</g; |
70
|
100
|
|
|
|
|
116
|
$d=~s/>/>/g; |
71
|
100
|
|
|
|
|
512
|
print $fh qq($self->{prefix} <$f>$d$f>\n); |
72
|
|
|
|
|
|
|
} |
73
|
37
|
|
|
|
|
156
|
print $fh qq($self->{prefix} $record>\n); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
########################################################### |
77
|
|
|
|
|
|
|
sub page_start |
78
|
|
|
|
|
|
|
{ |
79
|
10
|
|
|
10
|
0
|
13
|
my( $self, $name ) = @_; |
80
|
10
|
|
|
|
|
21
|
$self->{prefix} .= ' '; |
81
|
|
|
|
|
|
|
|
82
|
10
|
|
|
|
|
34
|
$name =~ s/\W/_/g; |
83
|
10
|
|
|
|
|
26
|
my $fh=$self->{fh}; |
84
|
10
|
|
|
|
|
41
|
print $fh "$self->{prefix}<$name>\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
########################################################### |
88
|
|
|
|
|
|
|
sub page_end |
89
|
|
|
|
|
|
|
{ |
90
|
10
|
|
|
10
|
0
|
17
|
my( $self, $name ) = @_; |
91
|
10
|
|
|
|
|
27
|
$name =~ s/\W/_/g; |
92
|
10
|
|
|
|
|
22
|
my $fh=$self->{fh}; |
93
|
10
|
|
|
|
|
27
|
print $fh "$self->{prefix}$name>\n"; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
48
|
substr( $self->{prefix} , -2 ) = ''; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |