line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::SubjectMap::XML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## helper functions for xml creation |
4
|
|
|
|
|
|
|
## internal use only |
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
46261
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
378
|
|
7
|
10
|
|
|
10
|
|
52
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
304
|
|
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
54
|
use base qw( Exporter ); |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
6196
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( element emptyElement esc startTag endTag comment ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub element { |
13
|
12
|
|
|
12
|
0
|
34
|
my ($tag,$content,@attrs) = @_; |
14
|
12
|
|
|
|
|
30
|
return startTag($tag,@attrs).esc($content).endTag($tag); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub emptyElement { |
18
|
0
|
|
|
0
|
0
|
0
|
my ($tag,@attrs) = @_; |
19
|
0
|
|
|
|
|
0
|
my $xml = startTag( $tag,@attrs); |
20
|
0
|
|
|
|
|
0
|
$xml =~ s{>$}{ />}; |
21
|
0
|
|
|
|
|
0
|
return $xml; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub startTag { |
25
|
14
|
|
|
14
|
0
|
34
|
my ($tag,@attrs) = @_; |
26
|
14
|
|
|
|
|
29
|
my $xml = "<$tag"; |
27
|
14
|
|
|
|
|
34
|
while ( @attrs ) { |
28
|
8
|
|
|
|
|
18
|
my $key = shift(@attrs); |
29
|
8
|
|
|
|
|
17
|
my $val = esc( shift(@attrs) ); |
30
|
8
|
|
|
|
|
32
|
$xml .= qq( $key="$val"); |
31
|
|
|
|
|
|
|
} |
32
|
14
|
|
|
|
|
19
|
$xml .= ">"; |
33
|
14
|
|
|
|
|
43
|
return $xml; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub endTag { |
37
|
14
|
|
|
14
|
0
|
17
|
my $tag = shift; |
38
|
14
|
|
|
|
|
67
|
return ( "$tag>" ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub esc { |
42
|
27
|
|
|
27
|
0
|
46
|
my $str = shift; |
43
|
27
|
50
|
|
|
|
57
|
return "" if ! defined($str); |
44
|
27
|
|
|
|
|
44
|
$str =~ s/</g; |
45
|
27
|
|
|
|
|
35
|
$str =~ s/>/>/g; |
46
|
|
|
|
|
|
|
## be careful not to encode ampersands that are valid entities |
47
|
27
|
|
|
|
|
48
|
$str =~ s/&(?!(amp|apos|lt|gt);)/&/g; |
48
|
27
|
|
|
|
|
626
|
return $str; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub comment { |
52
|
0
|
|
|
0
|
0
|
|
my $str = shift; |
53
|
0
|
|
|
|
|
|
return qq(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|