[xml] Big clean up in XPath

Date view Thread view Subject view Author view

From: TOM (ptittom@free.fr)
Date: Wed Oct 25 2000 - 19:33:16 EDT


Hi,
The attached patch fixes many bugs in XPath implementation:
 - errors in function names (local-name() and namespace-uri(), not
local-part() and namespace(); C function names now are
xmlXPathLocalNameFunction() and xmlXPathNamespaceURIFunction())

 - some functions didn't allow optional arguments (xmlXPathLocalName(),
xmlXPathNameFunction(), xmlXPathStringFunction(),
xmlXPathNumberFunction(),

 - adds the sum() function

 - implements some TODO parts (xmlXPathIdFunction() with node-set
argument, xmlXPathNormalizeFunction()

 - change xmlXPathFloorFunction(), xmlXPathCeilingFunction() and
xmlXPathRoundFunction() to use floor() and ceil() if we have math.h

 - add the description of the -xptr option in testXPath's help message

 - some corrections in help comments (xmlXPathStringEvalNumber() and
xmlXPathEvalNumber() : the BUG was already fixed and the Number definition
wasn't the one of the Recommandation)

 - rename xmlXPathMINF to xmlXPathNINF (I think in xmlXPathPINF PINF
means Positive INFinity, then it should be xmlXPathNINF for Negative
INFinity)

There are still big bugs (I don't yet try to fix them) :
 - it is always assumed node-sets are ordered in document order, it
isn't always the case (with the ancestor, ancestor-or-self, preceding and
preceding-sibling [and parent] axes). We probably need an
xmlXPathNodeSetGetFirst() function to get the node in the node-set that appears first in
document order.

 - the same lack of ordering rigour leads
"/EXAMPLE/chapter[last()]/preceding-sibling::chapter[1]" (should select /EXAMPLE/chapter[last() - 1])
and "(/EXAMPLE/chapter[last()]/preceding-sibling::chapter)[1]" (should
select /EXAMPLE/chapter[1]) to be equivalent (always selects
/EXAMPLE/chapter[last() - 1]). We probably need ordering functions.

 - doesn't seem there is a namespace support for functions (last() is
equivalent to foo:last() and bar:last()), it'll be necessary for
proprietary XPath extension functions.

 - number() (xmlXPathNumberFunction() or xmlXPathStringEvalNumber())
should be rewritten to handle "flip sign": number("-1") evaluates to NaN
rather than -1. I didn't know what to change (it would be easier to modify
xmlXPathStringEvalNumber()) so I did nothing.

 - it seems impossible to pass node-sets (actually only relative paths
or abbreviated absolute paths, and the root node) to functions:
ptittom:~/libxml/devel$ ./testXPath --expr 'string(//title)'
Error xpath.c:2345: Invalid type
string(//title)
         ^
Segfault
ptittom:~/libxml/devel$ ./testXPath --expr 'string(title)'
Error xpath.c:4292: Invalid expression
number(title)
       ^
Error xpath.c:4070: Invalid expression
number(title)
       ^
Object is empty (NULL)
ptittom:~/libxml/devel$ ./testXPath --expr 'string(/)'
Error xpath.c:4824: Invalid expression
number(/)
        ^
Segfault

 - I don't understand why xmlXPathEval() (actually xmlXPathEvalExpr()
called within xmlXPathEval()) must return a node-set.
ptittom:~/libxml/devel$ ./testXPath --expr 'local-name(/EXAMPLE)'
Object is a string : EXAMPLE
ptittom:~/libxml/devel$ ./testXPath 'local-name(/EXAMPLE)'
xmlXPathEval: evaluation failed to return a node set
xmlXPathEval: 1 object left on the stack
Object is empty (NULL)

I hope forgetting nothing...

Note: I haven't yet applied the "big patch" you mentionned, hope this
won't break mine...


----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Oct 25 2000 - 19:43:32 EDT