Re: [xml] XPath on a subtree

On Sat, Mar 23, 2013 at 12:09:25PM +0000, Alex Bligh wrote:

On 23 Mar 2013, at 11:52, Daniel Veillard wrote:

  ctxt->node = node;

actually it's good to set the doc too at that point before reusing
the context in the loop.

      ctxt->doc = doc;

  res = xmlXPathEval("./foo..", ctxt);

of course the subtree query will have to be relative, i.e. not
starting by /

Ah! The point I'd missed is that you can set ctxt->node. I couldn't
see an API call to set the current node. Could I suggest this might
be a useful function (if only an inline) so it gets into the docs?

  I though I had added a macro but searched for it an no it's not there.
In the python bindings there is an extra function called


we could do something along this line in C or another way could be
to add a new function:

xmlXPathNodeEval(xmlNodePtr node, const xmlChar *str, xmlXPathContextPtr ctx)

 as a simple wrapper around xmlXPathEval

Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit | virtualization library

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