line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::DOM::XML_Base; |
2
|
1
|
|
|
1
|
|
37451
|
use XML::DOM; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { } |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package XML::DOM::Element; |
8
|
|
|
|
|
|
|
use strict; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $scheme_re = '[a-zA-Z][a-zA-Z0-9.+\-]*'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _isAbsolute { |
13
|
|
|
|
|
|
|
return shift =~ /^($scheme_re):/so ? 1 : 0 |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getBase { |
17
|
|
|
|
|
|
|
my ( $self ) = @_; |
18
|
|
|
|
|
|
|
my $parent = $self; |
19
|
|
|
|
|
|
|
my $fullbase = ''; |
20
|
|
|
|
|
|
|
do { |
21
|
|
|
|
|
|
|
if ( $parent->isa( 'XML::DOM::Element' ) ) { |
22
|
|
|
|
|
|
|
if ( my $base = $parent->getAttribute( 'xml:base' ) ) { |
23
|
|
|
|
|
|
|
$fullbase = $base.$fullbase; |
24
|
|
|
|
|
|
|
# [2] done |
25
|
|
|
|
|
|
|
if ( _isAbsolute( $fullbase ) ) { |
26
|
|
|
|
|
|
|
return $fullbase; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} while ( $parent = $parent->getParentNode() ); |
31
|
|
|
|
|
|
|
# [3,4] wasn't possible to get an absolute URI, so return the best |
32
|
|
|
|
|
|
|
# relative URI we have |
33
|
|
|
|
|
|
|
return $fullbase; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub getAttributeWithBase { |
37
|
|
|
|
|
|
|
my ( $self, $name ) = @_; |
38
|
|
|
|
|
|
|
# XML Base spec (http://www.w3.org/TR/xmlbase/) says: |
39
|
|
|
|
|
|
|
# The rules for determining the base URI can be summarized as follows (highest priority to lowest): |
40
|
|
|
|
|
|
|
# [1] The base URI is embedded in the document's content. |
41
|
|
|
|
|
|
|
# [2] The base URI is that of the encapsulating entity (message, document, or none). |
42
|
|
|
|
|
|
|
# [3] The base URI is the URI used to retrieve the entity. |
43
|
|
|
|
|
|
|
# [4] The base URI is defined by the context of the application. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $val = $self->getAttribute( $name ) or return undef; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# [1] done |
48
|
|
|
|
|
|
|
if ( _isAbsolute( $val ) ) { |
49
|
|
|
|
|
|
|
return $val; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
return $self->getBase().$val; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |