Re: [xml] Fwd: Patch: Null prefix namespaces not cloned



Quoting Daniel Veillard <veillard redhat com>:

On Tue, Feb 21, 2006 at 11:24:58AM +1300, Andrew Miller wrote:
Hi,

libxml2 currently does not handle namespaces correctly in all cases when
cloning
nodes.

I have attached a testcase(which demonstrates the bug using libgdome2.0.8.1
on
top of libxml2.2.6.23), and a patch for the issue.

The testcase tests 4 different cases, which you access by compiling with
-DTESTNUMBER=0 through to -DTESTNUMBER=3

  I don't understand the GDOME test, could you explain ?
It has 4 cases:
Case 0)
Create a document, document element has no prefix but has a namespace, then
clone the document element.
Case 1)
Create a document, document element has no prefix but has a namespace, then
clone the document and retrieve the document element from the cloned
document.
Case 2)
Create a document, document element has a prefix and a namespace, then
clone the document element.
Case 3)
Create a document, document element has a prefix and a namespace, then
clone the document and retrieve the document element from the cloned
document.

At the end of this, the (directly or indirectly cloned) document element is
tested to see if it has the correct namespace(which should match the original
namespace, if the implementation is correct).

I don't understand the patch especially the node->doc != doc test, please
elaborate, thanks !

The first check tests for cases where it doesn't make sense to search for the
namespace, and sets the ns to NULL in those cases. If the prefix is NULL, it is
clearly not sensible to search for a match by prefix(remember namespace is
defined if we get to that code). The document equality check is there because
prefixes from one document don't make sense in another document.

I added the root->parent->type == XML_ELEMENT_NODE check into the while loop
because xmlNewNs seems to want an element, and otherwise we traverse past the
document element and get the document.

The final else case creates a new namespace structure for the particular element
concerned if the prefix isn't found from either the new or the old node.

Best regards,
Andrew


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



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