Subject: | NOT_FOUND_ERR on removeAttribute under certain conditions |
(Using libxml-enno 1.02 from the perl-libxml-enno-1.02-15 RPM from RedHat 7.3 with perl v5.6.1 on a mostly stock RH7.3 box.)
Calling removeAttribute on an element with no attributes raises a NOT_FOUND_ERR exception. This exception doesn't occur if there are any attributes on the element even if none match the argument to removeAttribute.
The DOM spec doesn't list a NOT_FOUND_ERR exception for removeAttribute.
The code responsible appears to be the croak in XML/DOM.pm:
sub removeAttribute
{
my ($self, $name) = @_;
my $attr = $self->[_A];
unless (defined $attr)
{
croak new XML::DOM::DOMException (NOT_FOUND_ERR);
return;
}
Here is a demonstration script:
my $parser = new XML::DOM::Parser;
my $document1 = $parser->parse(<<EOF);
<?xml version="1.0" standalone='yes'?>
<main present="yes">
</main>
EOF
my $main1 = $document1->getDocumentElement;
print "Removing something from first document\n";
$main1->removeAttribute("something");
my $document2 = $parser->parse(<<EOF);
<?xml version="1.0" standalone='yes'?>
<main>
</main>
EOF
my $main2 = $document2->getDocumentElement;
print "Removing something from second document\n";
$main2->removeAttribute("something");