Ah. No, CDATA apparently doesn't help, and it would indeed be useless with attributes.
And indeed, Genx refuses to put control characters in the output stream.
However, I found that an AddText call with an empty string seems to consistently coerce Genx to flush whatever it had in buffer. At that point I can sneak anything I want into the stream before I resume business as usual:
my $str = '';
my $w = XML::Genx->new;
eval {
$w->StartDocSender( sub { $str .= shift; } );
$w->StartElementLiteral( 'foo' );
$w->AddText( 'bar' );
$w->AddText( '' );
$str .= chr 1;
$w->AddText( 'baz' );
$w->EndElement;
$w->EndDocument;
};
die "Writing XML failed: $@" if $@;
This works as expected and allows to send control characters in node content, though not in attributes.
Another alternative whose viability I can't tell is that Genx provides a genxScrubText call which simply brushes out anything illegal. Would that be acceptable? (I do wonder why we need to make it possible to send control characters in the tickers.) However, the problem here is that XML::Genx currently doesn't bind that function.
As for XML style, I agree that attributes should be avoided. I didn't understand this when I first learned of XML, but I've come to appreciate why it is common wisdom among more insightful people. Mixed content is also a pain when you're dealing with structured rather than “document-ish” data.
Makeshifts last the longest.
|