[xml] ID already defined in 2.9.2



Hi all;
I've seen a bug report (https://bugzilla.gnome.org/show_bug.cgi?id=737840#c4)
regarding a new error about ID's already defined that turned
up with 2.9.2, but we're encountering a somewhat different manifestation.

In the Perl program below (using XML::LibXML), we basically want
to replace an element that has an ID, with another element that
(ultimately) should have the same ID.

Unfortunately, when linked to libxml2 2.9.2, this results in an error:
  element c: validity error : ID b is already defined

The documentation of (XML::LibXML::Node) unbindNode makes clear
that it removes the node from the dom tree, but it is still
associated with the Document. It is not unreasonable to think
that the Document should remember that the ID is "defined";
and in fact it's not necessarily a bad thing that libxml2
should be checking that.

However, this never resulted in an error until 2.9.2.
So, I'm not sure whether this is necessarily a bug
report on 2.9.2, or a request for suggestions on how
best (via XML::LibXML) to cleanly _remove_ the record
of the id from the Document.

... or maybe _both_ :>

Thanks for any input;
bruce
#===========================================================================
#!/usr/perl/bin -w
use strict;
use warnings;

use XML::LibXML;

my $xml_content = <<EOL;
<?xml version="1.0" encoding="UTF-8"?>
<a xml:id="a">
<b xml:id="b"></b>
</a>
EOL

my $dom = XML::LibXML->load_xml(string => $xml_content, no_blanks => 1);

my $a = $dom->documentElement;
my $b = $a->firstChild;

$b->unbindNode();

my $c = $dom->createElement("c");
$c->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'id', "b");
$a->appendChild($c);

print $dom->toString(1),"\n";
#===========================================================================


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]