XML::Parser 可以很好地处理 CDATA 块。也许您需要更新 XML::Parser 或底层expat
库,或者您的问题可能出在其他地方。很难说,因为你没有证明你的问题。
use strict;
use warnings;
use feature qw( say );
use Data::Dumper qw( Dumper );
use XML::Parser qw( );
sub f {
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Useqq = 1;
return Dumper($_[0]);
}
my $parser = XML::Parser->new(
Handlers => {
Start => sub { say "Start of $_[1]"; },
End => sub { say "End of $_[1]"; },
Char => sub { say "Char: " . f($_[1]); },
},
);
$parser->parse(<<'__EOI__');
<root>
<![CDATA[
<html>
<foo>test > test</foo><br>
</html>
]]>
</root>
__EOI__
Start of root
Char: "\n"
Char: "\n"
Char: " <html>"
Char: "\n"
Char: " <foo>test > test</foo><br>"
Char: "\n"
Char: " </html>"
Char: "\n"
Char: "\n"
End of root