XML-RSS-Parser
view release on metacpan or search on metacpan
lib/XML/RSS/Parser/Util.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 . ']]>';
lib/XML/RSS/Parser/Util.pm view on Meta::CPAN
its siblings. This method is not a full featured XML
generator, and has its limitations, but should suffice in
most cases. Use with caution.
Passing a second optional parameter with the value of true
will add an XML 1.0 standard declaration to the returned
XML. The third parameter (also optional) parameter defines
the encoding to be used in the declaration. The default is
'utf-8'.
=item encode_xml ($string[, $nocdata])
XML encodes any characters in the string that are required
to be represented as entities. This method will attempt to
identify anything that looks like markup and CDATA encodes
it. This can optional be turned off by passing a second
parameter with a true value. The markup will be entity
encoded instead.
=back
( run in 0.614 second using v1.01-cache-2.11-cpan-454fe037f31 )