From e8d1bd9daa881b01259e83eab60df8cbb56785c6 Mon Sep 17 00:00:00 2001 From: "William M. Brack" Date: Tue, 23 Dec 2003 01:28:58 +0000 Subject: [PATCH] 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) --- ChangeLog | 5 +++++ xpath.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 511eb8b3..76dade79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Dec 23 09:29:14 HKT 2003 William Brack + + * 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 * parser.c xmlreader.c: change xmlReadFd() xmlCtxtReadFd() diff --git a/xpath.c b/xpath.c index 9d7187d8..d6205438 100644 --- a/xpath.c +++ b/xpath.c @@ -1475,6 +1475,7 @@ int xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) { int depth1, depth2; int attr1 = 0, attr2 = 0; + xmlNodePtr attrNode1 = NULL, attrNode2 = NULL; xmlNodePtr cur, root; if ((node1 == NULL) || (node2 == NULL)) @@ -1484,15 +1485,28 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) { */ if (node1->type == XML_ATTRIBUTE_NODE) { attr1 = 1; + attrNode1 = node1; node1 = node1->parent; } if (node2->type == XML_ATTRIBUTE_NODE) { attr2 = 1; + attrNode2 = node2; node2 = node2->parent; } 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); + } if (attr2 == 1) return(1); return(-1);