Re: [xml] xmlXPathEval(*str,*ctxt)
- From: "Robert G. Brown" <rgb phy duke edu>
- To: Daniel Veillard <veillard redhat com>
- Cc: xml gnome org
- Subject: Re: [xml] xmlXPathEval(*str,*ctxt)
- Date: Thu, 28 Mar 2002 11:48:06 -0500 (EST)
On Thu, 28 Mar 2002, Daniel Veillard wrote:
it's not a bug. ht eobject recturned will not be null in either
case, in both case it will be flagged as a being a node set in
the first case obj->nodeset is not NULL and is of zero len and in
the second case obj->nodeset is NULL.
They have the same semantic.
it simply won't allocate a node set array if not needed.
So from a practical point of view, I need to do something like:
xp_op = xmlXPathEval(xpath, xp_doc);
/* no such path in xp_doc */
if( xp_op == NULL ) {
if((verbose == DEBUG_ALL) || (verbose == DEBUG_EXTRACT_VALUES)){
printf("DEBUG_EXTRACT_VALUES: xpath %s not found! Returning NULL.\n",xpath);
}
/* Free the path objects so we don't leak */
xmlXPathFreeObject(xp_op);
return numvals;
}
/* A second way no path can be returned */
if( xp_op != NULL && xp_op->nodesetval == NULL) {
if((verbose == DEBUG_ALL) || (verbose == DEBUG_EXTRACT_VALUES)){
printf("DEBUG_EXTRACT_VALUES: xpath %s not found! Returning NULL.\n",xpath);
}
xmlXPathFreeObject(xp_op);
return numvals;
}
which does seem to work in my code, thanks!
You'll have to forgive my ignorance -- I'm trying to learn to use these
marvelous tools from the documentation (and source) as I haven't found a
whole lot of example xpath code out there, and the inline documentation
for xmlXPathEval(str,ctxt) says it returns:
"...the xmlXPathObjectPtr resulting from the evaluation or NULL."
which I interpreted to mean that if the path string didn't exist in the
associated context, it would return NULL directly instead of a non-NULL
pointer to an empty object (with no nodeset array), since I could see no
reason to ever need an empty object in association with a context EXCEPT
to test and see that it wasn't there. I tried following the source back
to figure this out but freely admit that the inline magic of:
ret->comp = xmlXPathNewCompExpr();
defeated me -- looks like it would take a day or two to figure out.
Is there a reason that an empty object is allocated and returned even if
the xpath doesn't exist in the associated context? What can one do with
with such an empty object?
rgb
--
Robert G. Brown http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567 Fax: 919-660-2525 email:rgb phy duke edu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]