Re: Bug in XML::Writer?
by Duncan Cameron other posts by this author
Oct 2 2005 1:29AM messages near this date
view in the new Beta List Site
Re: XML::SAX
|
RFC: XML::Composer
& XSLT At 2005-09-30, 05:11:31 you wrote:
> Hi all,
>
> I think I've found a bug in XML writer but before I file a bug report,
> I'd like to know if I've missed anything. Below is the smallest test
> case which reproduces the bug.
>
> 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.
>
> Is there something I'm missing?
XML::Writer overwrites the variable $t_param with the qualified name, 'test:parameter'. This
example shows it clearly
use strict;
use XML::Writer;
my $e = [ 'uri:test', 'parameter' ];
my $writer = XML::Writer-> new(
NAMESPACES => 1,
OUTPUT => \my $xml,
PREFIX_MAP => { 'uri:test' => 'test' },
);
print "element is initially $e @{$e}\n";
$writer-> startTag($e);
$writer-> characters('name eq "foo"');
$writer-> endTag;
$writer-> end;
print $xml;
print "element is now $e\n";
However, if you change your syntax slightly then you can workaround the problem
my $uri = 'uri:test';
my $element = 'parameter';
...
$writer-> startTag([ $uri, $element ]);
In this case it is the anonymous array ref that gets overwritten.
Raise that bug report!
Duncan
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|