Fixed xmlGetNodePath() to generate the node test "*" for elements in the
* tree.c: Fixed xmlGetNodePath() to generate the node test "*"
for elements in the default namespace, rather than generating
an unprefixed named node test and loosing the namespace
information.
diff --git a/ChangeLog b/ChangeLog
index efd73e4..105a876 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Jun 12 12:54:25 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
+
+ * tree.c: Fixed xmlGetNodePath() to generate the node test "*"
+ for elements in the default namespace, rather than generating
+ an unprefixed named node test and loosing the namespace
+ information.
+
Fri Jun 9 21:45:02 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* include/libxml/parser.h: Clarified in the docs that the tree
diff --git a/tree.c b/tree.c
index d382e29..b1cd106 100644
--- a/tree.c
+++ b/tree.c
@@ -4236,7 +4236,7 @@
const char *sep;
const char *name;
char nametemp[100];
- int occur = 0;
+ int occur = 0, generic;
if (node == NULL)
return (NULL);
@@ -4267,17 +4267,23 @@
sep = "/";
next = NULL;
} else if (cur->type == XML_ELEMENT_NODE) {
+ generic = 0;
sep = "/";
name = (const char *) cur->name;
if (cur->ns) {
- if (cur->ns->prefix != NULL)
+ if (cur->ns->prefix != NULL) {
snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s",
(char *)cur->ns->prefix, (char *)cur->name);
- else
- snprintf(nametemp, sizeof(nametemp) - 1, "%s",
- (char *)cur->name);
- nametemp[sizeof(nametemp) - 1] = 0;
- name = nametemp;
+ nametemp[sizeof(nametemp) - 1] = 0;
+ name = nametemp;
+ } else {
+ /*
+ * We cannot express named elements in the default
+ * namespace, so use "*".
+ */
+ generic = 1;
+ name = "*";
+ }
}
next = cur->parent;
@@ -4288,10 +4294,11 @@
tmp = cur->prev;
while (tmp != NULL) {
if ((tmp->type == XML_ELEMENT_NODE) &&
- (xmlStrEqual(cur->name, tmp->name)) &&
- ((tmp->ns == cur->ns) ||
- ((tmp->ns != NULL) && (cur->ns != NULL) &&
- (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix)))))
+ (generic ||
+ (xmlStrEqual(cur->name, tmp->name)) &&
+ ((tmp->ns == cur->ns) ||
+ ((tmp->ns != NULL) && (cur->ns != NULL) &&
+ (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))
occur++;
tmp = tmp->prev;
}
@@ -4299,10 +4306,11 @@
tmp = cur->next;
while (tmp != NULL && occur == 0) {
if ((tmp->type == XML_ELEMENT_NODE) &&
- (xmlStrEqual(cur->name, tmp->name)) &&
- ((tmp->ns == cur->ns) ||
- ((tmp->ns != NULL) && (cur->ns != NULL) &&
- (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix)))))
+ (generic ||
+ (xmlStrEqual(cur->name, tmp->name)) &&
+ ((tmp->ns == cur->ns) ||
+ ((tmp->ns != NULL) && (cur->ns != NULL) &&
+ (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))
occur++;
tmp = tmp->next;
}