Subject: | Entites in text sections cause loss of data. |
If you have a text section in your xml like so:
<tag>A & B</tag>
The expat parser will break that up into 3 cdata sections 'A ', '&', and ' B'. Currently the way the SVG::Parser::Expat::Text function is written each one of those cdata sections will overwrite the previous section so you'll end up with the data ' B'. Here's the fix I'm using. I'm not especially knowledgable about how the expat parser works so I figured that rather than a patch I'd just provide example code:
*{SVG::Parser::Expat::Text} = sub {
my ($parser,$expat,$text)=@_;
my $elements=$parser->{__elements};
return if $text=~/^\s*$/s; #ignore redundant whitespace
my $parent=$elements->[-1];
use Data::Dumper;
if(defined $parent->{-cdata}) {
$text = $parent->{-cdata} . $text;
}
$parent->cdata($text);
$parser->debug("CDATA","\"$text\"");
};