Re: [xml] Is it possible to do XPath queries in subtrees?



Steinar Bang wrote:
> Since the only function that create an xmlXPathContext is
> xmlPathNewContext() which takes xmlDoc argument, does this means that
> it's only possible to do XPath queries from the top of documents?

Here is my how I implement a 'Node::Find' method (warning: C++ ahead !)

template <typename string, typename convert>
inline BasicXPathResult<string, convert>
BasicNode<string, convert>::Find(const BasicXPath<string, convert> &xpath) const
{
  xmlXPathContext *ctxt = xmlXPathNewContext(mImpl->doc);
  ctxt->node = mImpl;
BasicXPathResult<string, convert> result(xmlXPathCompiledEval(xpath.mImpl, ctxt));
  xmlXPathFreeContext(ctxt);
  return result;
}

i.e. I explicitely set the 'node' member of the context variable
after it has been allocated.

Stefan






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