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.
This commit is contained in:
Kasimier T. Buchcik 2006-06-12 10:58:24 +00:00
parent 803e37ac2c
commit d38c63f329
2 changed files with 30 additions and 15 deletions

View File

@ -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

38
tree.c
View File

@ -4236,7 +4236,7 @@ xmlGetNodePath(xmlNodePtr node)
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 @@ xmlGetNodePath(xmlNodePtr node)
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 @@ xmlGetNodePath(xmlNodePtr node)
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 @@ xmlGetNodePath(xmlNodePtr node)
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;
}