[xml] xpath and xmlXPathObject::nodesetval, need clarification
- From: Viktor Åtujber <theultramage gmail com>
- To: xml gnome org
- Subject: [xml] xpath and xmlXPathObject::nodesetval, need clarification
- Date: Fri, 19 Jun 2009 08:57:54 +0200
Hi. Currently I'm investigating a possible bug in php's simplexml
module, where running certain queries return FALSE instead of an empty
container object. I have tracked it to the following piece of code:
xmlNodeSetPtr result;
xmlXPathObjectPtr retval;
...
retval = xmlXPathEval((xmlChar *)query, sxe->xpath);
...
result = retval->nodesetval;
if (!result) {
xmlXPathFreeObject(retval);
RETURN_FALSE;
}
Here, not having a 'nodesetval' pointer is treated as an error.
I have found that libxml's xmlXPathEval operation behaves quite
strangely, so I would like to know whether the following text is
intended behavior, and perhaps an explanation of why it is so:
1. xpath('/foo') <- returns nodesetval containing zero nodes
2. xpath('/@attr') <- returns nodesetval containing zero nodes
3. xpath('/foo/bar') <- returns nodesetval containing zero nodes
4. xpath('/foo/@attr') <- returns NULL nodesetval
All three return a result of type XPATH_NODESET. In all three cases,
the elements/attributes queried for are nonexistent.
The scenario occurs when trying to query for an attribute of an
element for which no match exists. A typical example - getting a list
of ids: xpath('/data/entry[$condition]/@id'). If $condition evaluates
to false for all data, I get the above situation.
Comments / suggestions on how to correct the above code are welcome.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]