XML-XOXO
view release on metacpan or search on metacpan
lib/XML/XOXO/Node.pm view on Meta::CPAN
my %Map = (
'&' => '&',
'"' => '"',
'<' => '<',
'>' => '>',
'\'' => '''
);
my $RE = join '|', keys %Map;
sub encode_xml {
my ( $str, $nocdata ) = @_;
return unless defined($str);
if (
!$nocdata
&& $str =~ m/
<[^>]+> ## HTML markup
| ## or
&(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?);
## something that looks like an HTML entity.
/x
) {
## If ]]> exists in the string, encode the > to >.
$str =~ s/]]>/]]>/g;
$str = '<![CDATA[' . $str . ']]>';
( run in 0.621 second using v1.01-cache-2.11-cpan-454fe037f31 )