1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-20 03:52:25 +03:00

small enhancement to xmlXPathCmpNodes to assure document order for

* xpath.c: small enhancement to xmlXPathCmpNodes to assure
  document order for attributes is retained (Bug 129331)
This commit is contained in:
William M. Brack
2003-12-23 01:28:58 +00:00
parent 4bc5f43064
commit e8d1bd9daa
2 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,8 @@
Tue Dec 23 09:29:14 HKT 2003 William Brack <wbrack@mmm.com.hk>
* xpath.c: small enhancement to xmlXPathCmpNodes to assure
document order for attributes is retained (Bug 129331)
Mon Dec 22 19:06:16 CET 2003 Daniel Veillard <daniel@veillard.com> Mon Dec 22 19:06:16 CET 2003 Daniel Veillard <daniel@veillard.com>
* parser.c xmlreader.c: change xmlReadFd() xmlCtxtReadFd() * parser.c xmlreader.c: change xmlReadFd() xmlCtxtReadFd()

16
xpath.c
View File

@@ -1475,6 +1475,7 @@ int
xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) { xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
int depth1, depth2; int depth1, depth2;
int attr1 = 0, attr2 = 0; int attr1 = 0, attr2 = 0;
xmlNodePtr attrNode1 = NULL, attrNode2 = NULL;
xmlNodePtr cur, root; xmlNodePtr cur, root;
if ((node1 == NULL) || (node2 == NULL)) if ((node1 == NULL) || (node2 == NULL))
@@ -1484,15 +1485,28 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
*/ */
if (node1->type == XML_ATTRIBUTE_NODE) { if (node1->type == XML_ATTRIBUTE_NODE) {
attr1 = 1; attr1 = 1;
attrNode1 = node1;
node1 = node1->parent; node1 = node1->parent;
} }
if (node2->type == XML_ATTRIBUTE_NODE) { if (node2->type == XML_ATTRIBUTE_NODE) {
attr2 = 1; attr2 = 1;
attrNode2 = node2;
node2 = node2->parent; node2 = node2->parent;
} }
if (node1 == node2) { if (node1 == node2) {
if (attr1 == attr2) if (attr1 == attr2) {
/* not required, but we keep attributes in order */
if (attr1 != 0) {
cur = attrNode2->prev;
while (cur != NULL) {
if (cur == attrNode1)
return (1);
cur = cur->prev;
}
return (-1);
}
return(0); return(0);
}
if (attr2 == 1) if (attr2 == 1)
return(1); return(1);
return(-1); return(-1);