Changed the flag to xmlDocCopyNode (and similar routines), previously used
* tree.c: Changed the flag to xmlDocCopyNode (and similar routines),
previously used only for recursion, to use a value of '2' to
indicate copy properties & namespaces, but not children.
* xinclude.c: changed the handling of ranges to use the above new
facility. Fixes Bug 134268.
diff --git a/ChangeLog b/ChangeLog
index 85bec30..78217e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Mar 10 00:12:31 HKT 2004 William Brack <wbrack@mmm.com.hk>
+
+ * tree.c: Changed the flag to xmlDocCopyNode (and similar routines),
+ previously used only for recursion, to use a value of '2' to
+ indicate copy properties & namespaces, but not children.
+ * xinclude.c: changed the handling of ranges to use the above new
+ facility. Fixes Bug 134268.
+
Tue Mar 9 18:48:51 HKT 2004 William Brack <wbrack@mmm.com.hk>
* win32/Makefile.bcb, win32/Makefile.mingw, win32/Makefile.msvc:
diff --git a/tree.c b/tree.c
index bd18fb6..8e9cbf6 100644
--- a/tree.c
+++ b/tree.c
@@ -3702,11 +3702,15 @@
* a copy of the namespace at the top of the copied tree if
* not available in the subtree.
* Hence two functions, the public front-end call the inner ones
+ * The argument "recursive" normally indicates a recursive copy
+ * of the node with values 0 (no) and 1 (yes). For XInclude,
+ * however, we allow a value of 2 to indicate copy properties and
+ * namespace info, but don't recurse on children.
*/
static xmlNodePtr
xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
- int recursive) {
+ int extended) {
xmlNodePtr ret;
if (node == NULL) return(NULL);
@@ -3733,7 +3737,7 @@
case XML_DOCB_DOCUMENT_NODE:
#endif
#ifdef LIBXML_TREE_ENABLED
- return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, recursive));
+ return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, extended));
#endif /* LIBXML_TREE_ENABLED */
case XML_DOCUMENT_TYPE_NODE:
case XML_NOTATION_NODE:
@@ -3792,7 +3796,7 @@
return(tmp);
}
- if (!recursive)
+ if (!extended)
goto out;
if (node->nsDef != NULL)
ret->nsDef = xmlCopyNamespaceList(node->nsDef);
@@ -3836,7 +3840,7 @@
ret->children = node->children;
}
ret->last = ret->children;
- } else if (node->children != NULL) {
+ } else if ((node->children != NULL) && (extended != 2)) {
ret->children = xmlStaticCopyNodeList(node->children, doc, ret);
UPDATE_LAST_CHILD_AND_PARENT(ret)
}
@@ -3890,17 +3894,19 @@
/**
* xmlCopyNode:
* @node: the node
- * @recursive: if 1 do a recursive copy.
+ * @extended: if 1 do a recursive copy (properties, namespaces and children
+ * when applicable)
+ * if 2 copy properties and namespaces (when applicable)
*
* Do a copy of the node.
*
* Returns: a new #xmlNodePtr, or NULL in case of error.
*/
xmlNodePtr
-xmlCopyNode(const xmlNodePtr node, int recursive) {
+xmlCopyNode(const xmlNodePtr node, int extended) {
xmlNodePtr ret;
- ret = xmlStaticCopyNode(node, NULL, NULL, recursive);
+ ret = xmlStaticCopyNode(node, NULL, NULL, extended);
return(ret);
}
@@ -3908,17 +3914,19 @@
* xmlDocCopyNode:
* @node: the node
* @doc: the document
- * @recursive: if 1 do a recursive copy.
+ * @extended: if 1 do a recursive copy (properties, namespaces and children
+ * when applicable)
+ * if 2 copy properties and namespaces (when applicable)
*
* Do a copy of the node to a given document.
*
* Returns: a new #xmlNodePtr, or NULL in case of error.
*/
xmlNodePtr
-xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int recursive) {
+xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int extended) {
xmlNodePtr ret;
- ret = xmlStaticCopyNode(node, doc, NULL, recursive);
+ ret = xmlStaticCopyNode(node, doc, NULL, extended);
return(ret);
}
@@ -4026,7 +4034,7 @@
/**
* xmlCopyDoc:
* @doc: the document
- * @recursive: if 1 do a recursive copy.
+ * @recursive: if not zero do a recursive copy.
*
* Do a copy of the document info. If recursive, the content tree will
* be copied too as well as DTD, namespaces and entities.
diff --git a/xinclude.c b/xinclude.c
index 3cf1f54..05e05ed 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -914,7 +914,8 @@
*/
if (level < 0) {
while (level < 0) {
- tmp2 = xmlDocCopyNode(listParent, target, 0);
+ /* copy must include namespaces and properties */
+ tmp2 = xmlDocCopyNode(listParent, target, 2);
xmlAddChild(tmp2, list);
list = tmp2;
listParent = listParent->parent;
@@ -960,7 +961,8 @@
} else { /* ending node not a text node */
endLevel = level; /* remember the level of the end node */
endFlag = 1;
- tmp = xmlDocCopyNode(cur, target, 0);
+ /* last node - need to take care of properties + namespaces */
+ tmp = xmlDocCopyNode(cur, target, 2);
if (list == NULL) {
list = tmp;
listParent = cur->parent;
@@ -1007,7 +1009,11 @@
last = list = tmp;
listParent = cur->parent;
} else { /* Not text node */
- tmp = xmlDocCopyNode(cur, target, 0);
+ /*
+ * start of the range - need to take care of
+ * properties and namespaces
+ */
+ tmp = xmlDocCopyNode(cur, target, 2);
list = last = tmp;
listParent = cur->parent;
if (index1 > 1) { /* Do we need to position? */
@@ -1040,7 +1046,11 @@
/* Humm, should not happen ! */
break;
default:
- tmp = xmlDocCopyNode(cur, target, 0);
+ /*
+ * Middle of the range - need to take care of
+ * properties and namespaces
+ */
+ tmp = xmlDocCopyNode(cur, target, 2);
break;
}
if (tmp != NULL) {