Subject: | Broken namespace report |
use XML::Writer;
my $t_param = [ 'uri:test', 'parameter' ];
my $writer = XML::Writer->new(
NAMESPACES => 1,
OUTPUT => \my $xml,
PREFIX_MAP => { 'uri:test' => 'test' },
);
$writer->startTag($t_param);
$writer->characters('name eq "foo"');
$writer->endTag;
$writer->startTag($t_param); # this has the error
$writer->characters(20);
$writer->endTag;
$writer->end;
print $xml;
That generates the error:
Element name 'test:parameter' contains a colon. at xml.pl line 15
Note that it's the *second* instance of that which causes the error.
Comment out that line and the next two lines and it creates valid XML.
In response to an email about this, another person wrote:
Yes, the problem is that startTag *modifies* the array ref
passed to prefx:localname so the second time round you are
just passing the prefixed string.
Work around is easy:
my $ns = 'uri:test';
$writer->startTag([ $ns, 'parameter' ])
Being forced to constantly use the latter syntax makes it more difficult to factor out the common bits.
Cheers,
Ovid