| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::RSS::Parser::Util; |
|
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
59
|
|
|
5
|
|
|
|
|
|
|
@XML::RSS::Parser::Util::ISA = qw( Exporter ); |
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw( @EXPORT_OK ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
57
|
|
|
7
|
|
|
|
|
|
|
@EXPORT_OK = qw( as_xml encode_xml ); |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use XML::Elemental::Util qw( process_name ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
715
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# This has its limitations, but should suffice |
|
12
|
|
|
|
|
|
|
sub as_xml { |
|
13
|
0
|
|
|
0
|
1
|
|
my($node,$dec,$encoding) = @_; |
|
14
|
0
|
|
0
|
|
|
|
$encoding ||= 'utf-8'; |
|
15
|
0
|
0
|
|
|
|
|
my $xml = $dec ? qq(\n) : ''; |
|
16
|
0
|
|
|
|
|
|
my $dumper; |
|
17
|
|
|
|
|
|
|
$dumper = sub { |
|
18
|
0
|
|
|
0
|
|
|
my $node = shift; |
|
19
|
0
|
0
|
|
|
|
|
return encode_xml($node->data) |
|
20
|
|
|
|
|
|
|
if (ref($node) eq 'XML::RSS::Parser::Characters'); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# it must be an element then. |
|
23
|
0
|
|
|
|
|
|
my ($name, $ns) = process_name($node->name); |
|
24
|
0
|
|
|
|
|
|
my $prefix = $XML::RSS::Parser::xpath_ns{$ns}; # missing namespace??? |
|
25
|
0
|
0
|
0
|
|
|
|
$name = "$prefix:$name" if ($prefix && $prefix ne '#default'); |
|
26
|
0
|
|
|
|
|
|
my $xml = "<$name"; |
|
27
|
0
|
|
|
|
|
|
my $a = $node->attributes; |
|
28
|
0
|
|
|
|
|
|
my $children = $node->contents; |
|
29
|
0
|
|
|
|
|
|
foreach (keys %$a) { |
|
30
|
0
|
|
|
|
|
|
my ($aname, $ans) = process_name($_); |
|
31
|
0
|
0
|
|
|
|
|
if ($ans ne $ns) { |
|
32
|
0
|
|
|
|
|
|
my $aprefix = |
|
33
|
|
|
|
|
|
|
$XML::RSS::Parser::xpath_ns{$ans}; # missing namespace??? |
|
34
|
0
|
0
|
0
|
|
|
|
$aname = "$aprefix:$aname" |
|
35
|
|
|
|
|
|
|
if ($aprefix && $aprefix ne '#default'); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
0
|
|
|
|
|
|
$xml .= " $aname=\"" . encode_xml($a->{$_}, 1) . "\""; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
0
|
0
|
|
|
|
|
if ($children) { |
|
40
|
0
|
|
|
|
|
|
$xml .= '>'; |
|
41
|
0
|
|
|
|
|
|
map { $xml .= $dumper->($_) } @$children; |
|
|
0
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$xml .= "$name>"; |
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
|
$xml .= '/>'; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
|
|
|
|
|
$xml; |
|
47
|
0
|
|
|
|
|
|
}; |
|
48
|
0
|
|
|
|
|
|
$xml .= $dumper->($node); |
|
49
|
0
|
|
|
|
|
|
$xml; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my %Map = ( |
|
53
|
|
|
|
|
|
|
'&' => '&', |
|
54
|
|
|
|
|
|
|
'"' => '"', |
|
55
|
|
|
|
|
|
|
'<' => '<', |
|
56
|
|
|
|
|
|
|
'>' => '>', |
|
57
|
|
|
|
|
|
|
'\'' => ''' |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
my $RE = join '|', keys %Map; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub encode_xml { |
|
62
|
0
|
|
|
0
|
1
|
|
my ($str, $nocdata) = @_; |
|
63
|
0
|
0
|
|
|
|
|
return unless defined($str); |
|
64
|
0
|
0
|
0
|
|
|
|
if ( |
|
65
|
|
|
|
|
|
|
!$nocdata |
|
66
|
|
|
|
|
|
|
&& $str =~ m/ |
|
67
|
|
|
|
|
|
|
<[^>]+> ## HTML markup |
|
68
|
|
|
|
|
|
|
| ## or |
|
69
|
|
|
|
|
|
|
&(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?); |
|
70
|
|
|
|
|
|
|
## something that looks like an HTML entity. |
|
71
|
|
|
|
|
|
|
/x |
|
72
|
|
|
|
|
|
|
) { |
|
73
|
|
|
|
|
|
|
## If ]]> exists in the string, encode the > to >. |
|
74
|
0
|
|
|
|
|
|
$str =~ s/]]>/]]>/g; |
|
75
|
0
|
|
|
|
|
|
$str = ''; |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
0
|
|
|
|
|
|
$str =~ s!($RE)!$Map{$1}!g; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
0
|
|
|
|
|
|
$str; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |