Re: [xml] relative xpath matches nodes anywhere in tree

On Fri, May 25, 2012 at 10:44:35AM -0400, Noam Postavsky wrote:
On Fri, May 25, 2012 at 4:44 AM, Daniel Veillard <veillard redhat com> wrote:
 Actually the error is in --xpath implementation in xmllint :-)

static void doXPathQuery(
   ctxt->node = xmlDocGetRootElement(doc);
   res = xmlXPathEval(BAD_CAST query, ctxt);

 here the initialization is done with the Root element instead of
doc itself which is the classic initialization of the context node when
none is specified, leading to the error,

Ah, in that case it would be helpful if the documentation mentioned
the correct way to initialize. Using the doc to indicate that the
context is Root seems surprising to me.

  The problem is that XPath doesn't define a "default" value for the
context node. Somehow in XSLT, processing starts at the document node
and that's why I think it makes sense to use this ...

  xmlXPathNewContext doesn't set the context node, it set it to NULL,
if you keep it NULL all relative evaluations will fail (which sounds
the right thing to me at the XPath level) but kind of weird from an
user point of view, so initializing to the document node sounds the best
to me.

PS this came up because of an XMLStarlet bug report:

 I think that's unrelated :-)

Actually it is related, because XMLStarlet has the exact same bug as xmllint.

  okay, but a priori that's not the same initialization code path, i.e.
different bug :-)


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]