line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: SAX1toSAX2.pm,v 1.4 2002/07/08 11:56:04 matt Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package XML::Filter::SAX1toSAX2; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
6108
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
75
|
|
6
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION @ISA); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
104
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2714
|
use XML::SAX::Base; |
|
2
|
|
|
|
|
47757
|
|
|
2
|
|
|
|
|
77
|
|
9
|
2
|
|
|
2
|
|
2227
|
use XML::NamespaceSupport; |
|
2
|
|
|
|
|
6143
|
|
|
2
|
|
|
|
|
1132
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(XML::SAX::Base); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub start_document { |
16
|
0
|
|
|
0
|
1
|
|
my ($self, $document) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$self->{NSSupport} = XML::NamespaceSupport->new({ xmlns => 1 }); |
19
|
0
|
|
|
|
|
|
$self->SUPER::start_document($document); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub start_element { |
23
|
0
|
|
|
0
|
1
|
|
my ($self, $element) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$self->{NSSupport}->push_context; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->make_sax2_attribs($element); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
foreach my $prefix ($self->{NSSupport}->get_declared_prefixes) { |
30
|
|
|
|
|
|
|
# warn("start_prefix_mapping: $prefix\n"); |
31
|
0
|
|
|
|
|
|
$self->SUPER::start_prefix_mapping( |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
Prefix => $prefix, |
34
|
|
|
|
|
|
|
NamespaceURI => $self->{NSSupport}->get_uri($prefix), |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ($uri, $prefix, $lname) = $self->{NSSupport}->process_element_name($element->{Name}); |
40
|
0
|
|
|
|
|
|
$element->{LocalName} = $lname; |
41
|
0
|
|
|
|
|
|
$element->{Prefix} = $prefix; |
42
|
0
|
|
|
|
|
|
$element->{NamespaceURI} = $uri; |
43
|
0
|
|
|
|
|
|
$self->SUPER::start_element($element); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub end_element { |
47
|
0
|
|
|
0
|
1
|
|
my ($self, $element) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
foreach my $prefix ($self->{NSSupport}->get_declared_prefixes) { |
50
|
|
|
|
|
|
|
# warn("end_prefix_mapping: $prefix\n"); |
51
|
0
|
|
|
|
|
|
$self->SUPER::end_prefix_mapping( |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
Prefix => $prefix, |
54
|
|
|
|
|
|
|
NamespaceURI => $self->{NSSupport}->get_uri($prefix), |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
delete($self->{Attributes}); # just in case |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my ($uri, $prefix, $lname) = $self->{NSSupport}->process_element_name($element->{Name}); |
62
|
|
|
|
|
|
|
# warn("$element->{Name} => $uri, $lname, $prefix\n"); |
63
|
0
|
|
|
|
|
|
$element->{LocalName} = $lname; |
64
|
0
|
|
|
|
|
|
$element->{Prefix} = $prefix; |
65
|
0
|
|
|
|
|
|
$element->{NamespaceURI} = $uri; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->{NSSupport}->pop_context; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->SUPER::end_element($element); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub make_sax2_attribs { |
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
my $element = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->_scan_namespaces(%{$element->{Attributes}}); |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my %attribs; |
79
|
0
|
|
|
|
|
|
foreach my $key (keys %{$element->{Attributes}}) { |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my ($uri, $prefix, $lname) = $self->{NSSupport}->process_attribute_name($key); |
81
|
0
|
|
|
|
|
|
$attribs{"{$uri}$lname"} = { |
82
|
|
|
|
|
|
|
Name => $key, |
83
|
|
|
|
|
|
|
Value => $element->{Attributes}{$key}, |
84
|
|
|
|
|
|
|
Prefix => $prefix, |
85
|
|
|
|
|
|
|
NamespaceURI => $uri, |
86
|
|
|
|
|
|
|
LocalName => $lname, |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$element->{Attributes} = \%attribs; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _scan_namespaces { |
94
|
0
|
|
|
0
|
|
|
my ($self, %attributes) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
while (my ($attr_name, $value) = each %attributes) { |
97
|
0
|
0
|
|
|
|
|
if ($attr_name =~ /^xmlns(:(.*))?$/) { |
98
|
0
|
|
0
|
|
|
|
my $prefix = $2 || ''; |
99
|
|
|
|
|
|
|
# warn("declare_prefix: $prefix = $value\n"); |
100
|
0
|
|
|
|
|
|
$self->{NSSupport}->declare_prefix($prefix, $value) |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |