[xml] Multiple XPath Contexts...



Title: Multiple XPath Contexts...

Greetings -

I am attempting to translate a library that currently uses msxml (boo!) to libxml (yay!).  Unfortunately, I'm encountering some difficulties - and after scouring the list archives, I've decided that I need to ask a few questions in order to solve my problems.

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 should each context create its own xmlXPathContextPtr?  That certainly 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 sufficient, or do I have to copy other fields, too?  I don't want two pointers to the same xmlXPathContext - I want to end up with two independent xmlXPathContextPtr values that are otherwise indistinguishable.

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

Are contexts transitory (do you create them just before an xmlXPathEval, and destroy them immediately after?) or do you need to keep them around so their results will remain valid?  Will the result of xmlXPathEval(xPath, context) only be valid as long as the context hasn't been modified?  Will I be able to traverse the nodesetval, even if I do xmlXPathFreeContext(context)?  Do I have to somehow copy the nodesetval out of the result, if I want to keep it, 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])?

Thanks for any help you can give!

-Matt
// Matt Cruikshank (763)852-4183
// <mcruikshank vitalimages com>
void s(int&A,int&B){A^=B^=A^=B;}



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