[xml] xmlStaticCopyNode and namespaces
- From: Charlie Bozeman <cbozeman HiWAAY net>
- To: xml gnome org
- Subject: [xml] xmlStaticCopyNode and namespaces
- Date: Wed, 09 Jan 2002 22:04:51 -0600
My application copies branches from one part of a document to another
part using xmlDocCopyNode. Later when processing the new branches the
test for namespace equality fails:
if (node->ns == ns)
This failure is because the new branch nodes namespaces are copies of
the original namespace i.e. the namespace contents are equal but the
pointers are different. I traced the problem to xmlStaticCopyNode
starting at 2794:
if (node->ns != NULL) {
xmlNsPtr ns;
******************************************************************************
the next line will always fail because there is no namespace in the
"ret" node
******************************************************************************
ns = xmlSearchNs(doc, ret, node->ns->prefix);
if (ns == NULL) {
/*
* Humm, we are copying an element whose namespace is
defined
* out of the new tree scope. Search it in the original tree
* and add it at the top of the new tree
*/
ns = xmlSearchNs(node->doc, node, node->ns->prefix);
if (ns != NULL) {
xmlNodePtr root = ret;
while (root->parent != NULL) root = root->parent;
ret->ns = xmlNewNs(root, ns->href, ns->prefix);
}
} else {
/*
* reference the existing namespace definition in our own
tree.
*/
ret->ns = ns;
}
The attached patch checks if the intended copy is an out-of-tree copy
before making copies of the namespaces.
Charlie Bozeman
Index: tree.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/tree.c,v
retrieving revision 1.174
diff -c -r1.174 tree.c
*** tree.c 2002/01/06 23:05:13 1.174
--- tree.c 2002/01/10 03:07:37
***************
*** 2795,2804 ****
ret->nsDef = xmlCopyNamespaceList(node->nsDef);
if (node->ns != NULL) {
- xmlNsPtr ns;
! ns = xmlSearchNs(doc, ret, node->ns->prefix);
! if (ns == NULL) {
/*
* Humm, we are copying an element whose namespace is defined
* out of the new tree scope. Search it in the original tree
--- 2795,2807 ----
ret->nsDef = xmlCopyNamespaceList(node->nsDef);
if (node->ns != NULL) {
! /*
! * is this an out-of-tree copy
! */
! if (node->doc != doc) {
! xmlNsPtr ns;
!
/*
* Humm, we are copying an element whose namespace is defined
* out of the new tree scope. Search it in the original tree
***************
*** 2815,2821 ****
/*
* reference the existing namespace definition in our own tree.
*/
! ret->ns = ns;
}
}
if (node->properties != NULL)
--- 2818,2824 ----
/*
* reference the existing namespace definition in our own tree.
*/
! ret->ns = node->ns;
}
}
if (node->properties != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]