1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-21 14:53:44 +03:00

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> 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 * 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 *sep;
const char *name; const char *name;
char nametemp[100]; char nametemp[100];
int occur = 0; int occur = 0, generic;
if (node == NULL) if (node == NULL)
return (NULL); return (NULL);
@@ -4267,17 +4267,23 @@ xmlGetNodePath(xmlNodePtr node)
sep = "/"; sep = "/";
next = NULL; next = NULL;
} else if (cur->type == XML_ELEMENT_NODE) { } else if (cur->type == XML_ELEMENT_NODE) {
generic = 0;
sep = "/"; sep = "/";
name = (const char *) cur->name; name = (const char *) cur->name;
if (cur->ns) { if (cur->ns) {
if (cur->ns->prefix != NULL) if (cur->ns->prefix != NULL) {
snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s",
(char *)cur->ns->prefix, (char *)cur->name); (char *)cur->ns->prefix, (char *)cur->name);
else nametemp[sizeof(nametemp) - 1] = 0;
snprintf(nametemp, sizeof(nametemp) - 1, "%s", name = nametemp;
(char *)cur->name); } else {
nametemp[sizeof(nametemp) - 1] = 0; /*
name = nametemp; * We cannot express named elements in the default
* namespace, so use "*".
*/
generic = 1;
name = "*";
}
} }
next = cur->parent; next = cur->parent;
@@ -4288,10 +4294,11 @@ xmlGetNodePath(xmlNodePtr node)
tmp = cur->prev; tmp = cur->prev;
while (tmp != NULL) { while (tmp != NULL) {
if ((tmp->type == XML_ELEMENT_NODE) && if ((tmp->type == XML_ELEMENT_NODE) &&
(xmlStrEqual(cur->name, tmp->name)) && (generic ||
((tmp->ns == cur->ns) || (xmlStrEqual(cur->name, tmp->name)) &&
((tmp->ns != NULL) && (cur->ns != NULL) && ((tmp->ns == cur->ns) ||
(xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))) ((tmp->ns != NULL) && (cur->ns != NULL) &&
(xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))
occur++; occur++;
tmp = tmp->prev; tmp = tmp->prev;
} }
@@ -4299,10 +4306,11 @@ xmlGetNodePath(xmlNodePtr node)
tmp = cur->next; tmp = cur->next;
while (tmp != NULL && occur == 0) { while (tmp != NULL && occur == 0) {
if ((tmp->type == XML_ELEMENT_NODE) && if ((tmp->type == XML_ELEMENT_NODE) &&
(xmlStrEqual(cur->name, tmp->name)) && (generic ||
((tmp->ns == cur->ns) || (xmlStrEqual(cur->name, tmp->name)) &&
((tmp->ns != NULL) && (cur->ns != NULL) && ((tmp->ns == cur->ns) ||
(xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))) ((tmp->ns != NULL) && (cur->ns != NULL) &&
(xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))
occur++; occur++;
tmp = tmp->next; tmp = tmp->next;
} }