/usr/share/perl5/SVG/XML.pm is in libsvg-perl 2.59-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | =pod
=head1 NAME
SVG::XML - Handle the XML generation bits for SVG.pm
=head1 AUTHOR
Ronan Oger, cpan@roitsystems.com
=head1 SEE ALSO
L<SVG>,L<SVG::XML>,L<SVG::Element>,L<SVG::Parser>
L<http://www.roitsystems.com/> ROASP.com: Serverside SVG server
L<http://www.roitsystems.com/> ROIT Systems: Commercial SVG perl solutions
L<http://www.w3c.org/Graphics/SVG/> SVG at the W3C
=cut
package SVG::XML;
use strict;
use warnings;
use Exporter qw(import);
our $VERSION = '2.59';
our @EXPORT = qw(
xmlesc
xmlescape
xmlescp
cssstyle
xmlattrib
xmlcomment
xmlpi
xmltag
xmltagopen
xmltagclose
xmltag_ln
xmltagopen_ln
xmltagclose_ln
processtag
xmldecl
dtddecl
);
sub xmlescp {
my ($self,$s) = @_;
$s = '0' unless defined $s;
$s=join(', ',@{$s}) if(ref($s) eq 'ARRAY');
# Special XML entities are escaped
$s=~s/&(?!#(x\w\w|\d+?);)/&/g;
$s=~s/>/>/g;
$s=~s/</</g;
$s=~s/\"/"/g;
$s=~s/\'/'/g;
# Backtick is just a regular XML citizen
#$s=~s/\`/'/g;
# Invalid XML characters are removed, not just escaped: \x00-\x08\x0b\x1f
# Tabs (\x09) and newlines (\x0a) are valid.
while ( $s=~s/([\x00-\x08\x0b\x1f])/''/e ) {
my $char = "'\\x".sprintf('%02X',ord($1))."'";
$self->error( $char => "This forbidden XML character was removed");
}
# Per suggestion from Adam Schneider
$s=~s/([\200-\377])/'&#'.ord($1).';'/ge;
return $s;
}
*xmlesc=\&xmlescp;
*xmlescape=\&xmlescp;
sub cssstyle {
my %attrs=@_;
return(join('; ',map { qq($_: ).$attrs{$_} } keys(%attrs)));
}
# Per suggestion from Adam Schneider
sub xmlattrib {
my %attrs=@_;
return(join(' ',map { qq($_=").$attrs{$_}.q(") } sort keys(%attrs)));
}
sub xmltag {
my ($name,$ns,%attrs)=@_;
$ns=$ns?"$ns:":'';
my $at=' '.xmlattrib(%attrs)||'';
return qq(<$ns$name$at />);
}
sub xmltag_ln {
my ($name,$ns,%attrs)=@_;
return xmltag($name,$ns,%attrs);
}
sub xmltagopen {
my ($name,$ns,%attrs)=@_;
$ns=$ns?"$ns:":'';
my $at=' '.xmlattrib(%attrs)||'';
return qq(<$ns$name$at>);
}
sub xmltagopen_ln {
my ($name,$ns,%attrs)=@_;
return xmltagopen($name,$ns,%attrs);
}
sub xmlcomment {
my ($self,$r_comment) = @_;
my $ind = $self->{-docref}->{-elsep}.$self->{-docref}->{-indent} x $self->{-docref}->{-level};
return($ind.join($ind,map { qq(<!-- $_ -->)} @$r_comment));
}
sub xmlpi {
my ($self,$r_pi) = @_;
my $ind = $self->{-docref}->{-elsep}.$self->{-docref}->{-indent} x $self->{-docref}->{-level};
return(join($ind,map { qq(<?$_?>)} @$r_pi));
}
*processinginstruction=\&xmlpi;
sub xmltagclose {
my ($name,$ns)=@_;
$ns=$ns?"$ns:":'';
return qq(</$ns$name>);
}
sub xmltagclose_ln {
my ($name,$ns)=@_;
return xmltagclose($name,$ns);
}
sub dtddecl {
my $self = shift;
my $docroot = $self->{-docroot} || 'svg';
my $id;
if ($self->{-pubid}) {
$id = 'PUBLIC "'.$self->{-pubid}.'"';
$id .= ' "'.$self->{-sysid}.'"' if ($self->{-sysid});
} elsif (
$self->{-sysid}) {
$id = 'SYSTEM "'.$self->{-sysid}.'"';
} else {
$id = 'PUBLIC "-//W3C//DTD SVG 1.0//EN"' .
$self->{-docref}->{-elsep}.
"\"$self->{-docref}->{-dtd}\""
}
my $at = join(' ',($docroot, $id));
#>>>TBD: add internal() method to return this
my $extension = (exists $self->{-internal})?$self->{-internal}->render():"";
if (exists $self->{-extension} and $self->{-extension}) {
$extension .= $self->{-docref}{-elsep}.
$self->{-extension}.
$self->{-docref}{-elsep};
}
$extension = " [".$self->{-docref}{-elsep}.$extension."]" if $extension;
return qq[$self->{-docref}{-elsep}<!DOCTYPE $at$extension>];
}
sub xmldecl {
my $self = shift;
my $version= $self->{-version} || '1.0';
my $encoding = $self->{-encoding} || 'UTF-8';
my $standalone = $self->{-standalone} ||'yes';
return qq§<?xml version="$version" encoding="$encoding" standalone="$standalone"?>§;
}
#-------------------------------------------------------------------------------
1;
|