Subject: | Bug Report: setAttributeNS |
Date: | Thu, 25 Feb 2010 12:31:07 -0700 (MST) |
To: | bug-XML-LibXML [...] rt.cpan.org |
From: | Jonathon Duerig <duerig [...] flux.utah.edu> |
If an element contains both a default namespace declaration and a second
namespace declaration, adding an attribute using the default namespace
declaration will cause that attribute to have the other prefix.
OS Version: FreeBSD 6.3-RELEASE
Perl Version: v5.8.8
LibXML Version: 1.70
Consider the following example script:
=== BEGIN MINIMAL CASE ===
#!/usr/bin/perl -w
use strict;
use XML::LibXML;
my $xml_string = <<'XML';
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns="uri"
xmlns:wrong="other">
</element>
XML
my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($xml_string);
my $root = $doc->documentElement();
$root->setAttributeNS("uri", "prefix:attribute", "text");
print $doc->toString(1);
=== END MINIMAL CASE ===
This will emit the following text:
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns="uri" xmlns:wrong="other" wrong:attribute="text">
</element>
Notice the 'wrong:attribute', when the uri in setAttributeNS() was for the
default namespace. The call should have either added a new declaration
(xmlns:prefix="uri") along with the attribute (prefix:attribute="text") or
omitted the prefix altogether because the attribute was associated with an
element in the default namespace.
---
Broad audience or deep message: Pick one.