Subject: | Inconsistent prefixing of namespaces on attributes when using map_xmlns |
When using the map_xmlns parameter, attributes are _sometimes_ prefixed
with the tag's namespace, depending on if the namespace in question is
the default namespace or not. Attached is simple test demonstrating two
semantically equal XML fragments which XML::Twig parses differently,
because of this.
From the comments around line 2005 of Twig.pm, this is known to be a
somewhat weird edge case. I would think that taking the namespace from
the tag's namespace, and falling back to '#default' after that, would be
a more correct ordering.
- Alex
Subject: | test-xmlns-attr.t |
#!/usr/bin/perl -w
use Carp;
use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;
use strict;
use warnings;
$| = 1;
use XML::Twig;
my $TMAX = 4;
print "1..$TMAX\n";
my $default = <<EOT;
<?xml version="1.0" encoding="UTF-8"?>
<calendar-query xmlns:D="DAV:" xmlns="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag/>
</D:prop>
<filter>
<comp-filter name="VCALENDAR"/>
</filter>
</calendar-query>
EOT
my $explicit = <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav" >
<D:prop>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR"/>
</C:filter>
</C:calendar-query>
EOF
for my $text ($default, $explicit) {
my $t = XML::Twig->new(
map_xmlns => {
'urn:ietf:params:xml:ns:caldav' => 'C',
'DAV:' => 'D',
},
);
$t->parse($text);
my @nodes = $t->find_nodes("/C:calendar-query/C:filter/C:comp-filter" );
is(@nodes+0, 1, "Right number of nodes");
my %atts = %{ $nodes[0]->atts };
is( join("",keys %atts), "C:name", "Has the 'C:name' property'");
}
exit;
1;