[xml] XPath and abbreviated paths

Date view Thread view Subject view Author view

From: TOM (ptittom@free.fr)
Date: Fri Oct 27 2000 - 19:46:59 EDT


Hi,
I tried this:
ptittom:~/libxml/origin$ ./testXPath --expr //title
Error xpath.c:2345: Invalid type
//title
  ^
Object is empty (NULL)
ptittom:~/libxml/origin$ ./testXPath //title
Object is a Node Set :
Set contains 6 nodes:
1 ELEMENT title
2 ELEMENT title
3 ELEMENT title
4 ELEMENT title
5 ELEMENT title
6 ELEMENT title

The only difference when passing the --expr option is to call
xmlXPathEvalExpression() instead of xmlXPathEval(), and the (nearly)
only
difference between these two functions is to call xmlXPathRoot() (in
xmlXPathEval()) or not (in xmlXPathEvalExpression()).

If we call ./testXPath --expr /EXAMPLE//title, it works, and if we look
at xmlXPathEvalLocationPath(), we see that if the path begins with '//'
xmlXPathRoot() isn't called, but if it begins with a simple '/' it is.

I modified the function to always call xmlXPathRoot() if we havea
single
or double '/' at the beginning of the path and... it works!

There was a problem in xmlXPathEvalRelativeLocationPath() which handled
absolute paths !? I fixed it and xmlXPathEvalPathExpr() which called it
leaving a '/' before some steps (when we had a FilterExpr followed by a
single '/' and a RelativeLocationPath).

Another bug in xmlXPathEvalPathExpr() appears when we evaluate
predicates:
ptittom:~/libxml/origin$ ./testXPath //chapter[image]
Error xpath.c:4299: Invalid expression
//chapter[image]
          ^
Object is empty (NULL)
The function verify what's the character following a Name, to decide
whether we have a FunctionCall, a NodeType search or a RelativeLocationPath,
but not if we are at the ending square bracket of a Predicate. Fixed.

Yet another with the attribute axis and a NodeTest equal to '*' (@href
and attribute::href work well) :
ptittom:~/libxml/origin$ ./testXPath '//chapter/image/@*'
Object is a Node Set :
Set contains 0 nodes:
ptittom:~/libxml/origin$ ./testXPath '//chapter/image/@href'
Object is a Node Set :
Set contains 1 nodes:
1 ATTRIBUTE href
    TEXT
      content=linus.gif
It happens in xmlXPathNodeCollectAndTest() where the attribute and
namespace axes aren't handled.
I don't understand the meaning of the NODE_TEST_NS NodeTest and don't
know how to look for all namespace nodes. Although the attribute::* and @*
bug is fixed.
The tests on cur->type for the AXIS_ATTRIBUTE && NODE_TEST_ALL don't
seem required since the traversal functions are supposed to return only
nodes of this type but just in case I keep them...

We still need to fix the function calls when passing the root node (/)
as argument, it still segfaults in some functions (id, name and string at
least).
I think about adding a test in xmlXPathEvalLocationPath() not to call
xmlXPathRelativeLocationPath() if NXT(1) (the character following '/') is a
closing bracket, or return when we're in xmlXPathEvalStep() and can't
find a name (the error happens in xmlXPathEvalNodeSet(): pass a NULL name
and it can't find a Name so it XP_ERROR0(XPATH_EXPR_ERROR))

We also have to fix the function calls when passing as argument a
RelativeLocationPath beginning with a name (e.g. id(myNode) or
/EXAMPLE/chapter[count(title)])

It also seems most functions don't follow the Rec since they fail if the
argument isn't of the expected type instead of converting it.
Not fixed yet.

Tom


----
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 : Fri Oct 27 2000 - 20:43:34 EDT