Re: [xml] Multiple XPath Contexts...



On Wed, Feb 20, 2002 at 11:00:07AM -0600, Matt Cruikshank wrote:
Greetings -

  Hello,

I don't think I fully understand how to use xmlXPathContextPtr.  Is it best
thought of as a neighbor to xmlDocPtr, so you should modify
xmlXPathContextPtr->node every time you need to do a context switch?  Or

  yes. An xmlXPathContextPtr is a structure used to run an XPath query.
There is little depedancies between the xmlXPathContextPtr and the document,
basically only the ctxt->doc and the ctxt->node are related.
  However, a context may contain more environments settings like 
variables which may relate to that document, so it is better to
simply reallocate an xmlXPathContextPtr when you switch documents.

should each context create its own xmlXPathContextPtr?  That certainly

   What is a "context"  ?

sounds more logical - but if it's correct - how do I copy a context?  (I've
looked for a function to do it, and haven't found one.)  Do I simply copy
the xmlXPathContextPtr->node from one context to another?  Is that

   the node and doc fields are just pointer to the document, they are
not data allocated within the xmlXPathContextPtr, just references.

sufficient, or do I have to copy other fields, too?  I don't want two

   Why do you want to copy a context ?

pointers to the same xmlXPathContext - I want to end up with two independent
xmlXPathContextPtr values that are otherwise indistinguishable.

  I don't understand what you want to achieve. If you define function,
or variables bound to a given context you will have to redefine them similary
if you create a new one. There is no copy operation at that level.

To sum up my rambling : if I want to store a copy of a context, what is
required?

  I don't understand why. I would say taht in general you cannot because
the context may have variables defined and those variables may refer to
documents and copying those may not be p[ersistent if the document is not
persistent or not the same.

Are contexts transitory (do you create them just before an xmlXPathEval, and
destroy them immediately after?)

  They don't have to

or do you need to keep them around so their
results will remain valid?

   the result are XPath object. their lifetime is not related to the
context lifetime. It is related to the lifetime of the document they may
be pointing too, which sounds trivial if you think what an XPath query is.

Will the result of xmlXPathEval(xPath, context)
only be valid as long as the context hasn't been modified?  Will I be able

  No, c.f. just before

to traverse the nodesetval, even if I do xmlXPathFreeContext(context)?  Do I

  yes

have to somehow copy the nodesetval out of the result, if I want to keep it,

  No. Look at the testXPath.c code. But you will have to keep the document it
is pointing to.

even after the context changes?  Or should I preserve one and only one copy
of a xmlXPathContextPtr for the duration of a logical context (one for each
thread, for instance [don't worry - I'm using mutexes])?

  The context is just the amount of data need to run the computation.
The results are independants of it. They are dependant on the document
being queried

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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