1package XML::Liberal::Remedy::NestedCDATA;
2use strict;
3
4use HTML::Entities qw( encode_entities );
5
6sub apply {
7    my $class = shift;
8    my($driver, $error, $xml_ref) = @_;
9
10    return 0 if $error->message !~ /^parser error : Opening and ending tag mismatch:/;
11
12    while ($$xml_ref =~ /(?<= <!\[CDATA\[ ) (.*? \]\]> )/xmsg) {
13        my ($cdata, $start, $end) = ($1, $-[1], $+[1]);
14        next if $cdata !~ /<!\[CDATA\[/;
15        my $escaped = encode_entities($cdata, '<>&');
16        substr($$xml_ref, $start, $end - $start) = "]]>$escaped<![CDATA[";
17        return 1;
18    }
19
20    return 0;
21}
22
231;
24