Re: [xml] ID already defined in 2.9.2

On 18/12/2014 12:37, Bruce Miller wrote:
Hi all;
   I've seen a bug report (
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

Yes, this is a different manifestation.

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.

To work around this error, you can simply force the unbound node to be destroyed by removing any references to it. In your example program, add `$b = undef` after `$b->unbindNode()`. Alternatively, you could remove the `id` attribute after unbinding a node.

Of course, this only works if you really want to remove the node. It seems that libxml2 doesn't provide a useful mechanism to move ID attributes from one document to another. I think that `xmlSetTreeDoc` should be changed to account for added and removed IDs.


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