XML-XOXO

 view release on metacpan or  search on metacpan

lib/XML/XOXO/Node.pm  view on Meta::CPAN

my %Map = (
            '&'  => '&',
            '"'  => '"',
            '<'  => '&lt;',
            '>'  => '&gt;',
            '\'' => '&#39;'
);
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 &gt;.
        $str =~ s/]]>/]]&gt;/g;
        $str = '<![CDATA[' . $str . ']]>';



( run in 0.299 second using v1.01-cache-2.11-cpan-ec4f86ec37b )