line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::File::SAX; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## no POD here since you don't really want to use this module |
4
|
|
|
|
|
|
|
## directly. Look at MARC::File::XML instead. |
5
|
|
|
|
|
|
|
## |
6
|
|
|
|
|
|
|
## MARC::File::SAX is a SAX handler for parsing XML encoded using the |
7
|
|
|
|
|
|
|
## MARC21slim XML schema from the Library of Congress. It builds a MARC::Record |
8
|
|
|
|
|
|
|
## object up from SAX events. |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
## For more details see: http://www.loc.gov/standards/marcxml/ |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
159
|
|
13
|
4
|
|
|
4
|
|
2651
|
use XML::SAX; |
|
4
|
|
|
|
|
23624
|
|
|
4
|
|
|
|
|
231
|
|
14
|
4
|
|
|
4
|
|
31
|
use base qw( XML::SAX::Base ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
4552
|
|
15
|
4
|
|
|
4
|
|
73961
|
use Data::Dumper; |
|
4
|
|
|
|
|
15923
|
|
|
4
|
|
|
|
|
288
|
|
16
|
4
|
|
|
4
|
|
2503
|
use MARC::Charset qw(utf8_to_marc8); |
|
4
|
|
|
|
|
270657
|
|
|
4
|
|
|
|
|
1840
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub start_element { |
19
|
0
|
|
|
0
|
1
|
|
my ( $self, $element ) = @_; |
20
|
0
|
|
|
|
|
|
my $name = $element->{ Name }; |
21
|
0
|
0
|
|
|
|
|
if ( $name eq 'leader' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->{ tag } = 'LDR'; |
23
|
|
|
|
|
|
|
} elsif ( $name eq 'controlfield' ) { |
24
|
0
|
|
|
|
|
|
$self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; |
25
|
|
|
|
|
|
|
} elsif ( $name eq 'datafield' ) { |
26
|
0
|
|
|
|
|
|
$self->{ tag } = $element->{ Attributes }{ '{}tag' }{ Value }; |
27
|
0
|
|
|
|
|
|
$self->{ i1 } = $element->{ Attributes }{ '{}ind1' }{ Value }; |
28
|
0
|
|
|
|
|
|
$self->{ i2 } = $element->{ Attributes }{ '{}ind2' }{ Value }; |
29
|
|
|
|
|
|
|
} elsif ( $name eq 'subfield' ) { |
30
|
0
|
|
|
|
|
|
$self->{ subcode } = $element->{ Attributes }{ '{}code' }{ Value }; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub end_element { |
35
|
0
|
|
|
0
|
1
|
|
my ( $self, $element ) = @_; |
36
|
0
|
|
|
|
|
|
my $name = $element->{ Name }; |
37
|
0
|
0
|
|
|
|
|
if ( $name eq 'subfield' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
push @{ $self->{ subfields } }, $self->{ subcode }; |
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ($self->{ transcode }) { |
41
|
0
|
|
|
|
|
|
push @{ $self->{ subfields } }, utf8_to_marc8($self->{ chars }); |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
|
push @{ $self->{ subfields } }, $self->{ chars } ; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->{ chars } = ''; |
47
|
0
|
|
|
|
|
|
$self->{ subcode } = ''; |
48
|
|
|
|
|
|
|
} elsif ( $name eq 'controlfield' ) { |
49
|
|
|
|
|
|
|
$self->{ record }->append_fields( |
50
|
|
|
|
|
|
|
MARC::Field->new( $self->{ tag }, $self->{ chars } ) |
51
|
0
|
|
|
|
|
|
); |
52
|
0
|
|
|
|
|
|
$self->{ chars } = ''; |
53
|
0
|
|
|
|
|
|
$self->{ tag } = ''; |
54
|
|
|
|
|
|
|
} elsif ( $name eq 'datafield' ) { |
55
|
|
|
|
|
|
|
$self->{ record }->append_fields( |
56
|
|
|
|
|
|
|
MARC::Field->new( |
57
|
|
|
|
|
|
|
$self->{ tag }, |
58
|
|
|
|
|
|
|
$self->{ i1 }, |
59
|
|
|
|
|
|
|
$self->{ i2 }, |
60
|
0
|
|
|
|
|
|
@{ $self->{ subfields } } |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
) |
62
|
|
|
|
|
|
|
); |
63
|
0
|
|
|
|
|
|
$self->{ tag } = ''; |
64
|
0
|
|
|
|
|
|
$self->{ i1 } = ''; |
65
|
0
|
|
|
|
|
|
$self->{ i2 } = ''; |
66
|
0
|
|
|
|
|
|
$self->{ subfields } = []; |
67
|
0
|
|
|
|
|
|
$self->{ chars } = ''; |
68
|
|
|
|
|
|
|
} elsif ( $name eq 'leader' ) { |
69
|
0
|
|
|
|
|
|
my $ldr = $self->{ chars }; |
70
|
0
|
0
|
0
|
|
|
|
$self->{ transcode }++ |
71
|
|
|
|
|
|
|
if (substr($ldr,9,1) eq 'a' and $self->{toMARC8}); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
substr($ldr,9,1,' ') if ($self->{ transcode }); |
74
|
0
|
|
|
|
|
|
$self->{ record }->leader( $ldr ); |
75
|
0
|
|
|
|
|
|
$self->{ chars } = ''; |
76
|
0
|
|
|
|
|
|
$self->{ tag } = ''; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub characters { |
82
|
0
|
|
|
0
|
1
|
|
my ( $self, $chars ) = @_; |
83
|
0
|
0
|
0
|
|
|
|
if ( $self->{ subcode } or ( $self->{ tag } and |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
84
|
|
|
|
|
|
|
( $self->{ tag } eq 'LDR' or $self->{ tag } < 10 ) ) ) { |
85
|
0
|
|
|
|
|
|
$self->{ chars } .= $chars->{ Data }; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |