Daniel, et al.,
Thanks for your response - your diligence amazes me. =)
> Why do you want to copy a context ?
Given the following XML :
<report>
<patient>Jones, Jon</patient>
<doctor>Mathews, Matt</doctor>
</report>
<patient>Williams, Wendy</patient>
<doctor>Trejo, Tony</doctor>
If I have an object that does the following :
// constructor...
_doc = xmlParseFile(fileName);
_context = xmlXPathNewContext(_doc);
// inside a function that changes the context...
_nodeList = xmlXPathEval("/report", _context);
_activeNode = _nodeList->nodesetval->nodeTab[0];
_context->node = _activeNode;
Then I have changed the context for future XPath evaluations.
Well, like I said, I'm translating a library from msxml (boo!) to libxml (yay!), and the class that I'm working on supports a copy constructor.
So, if I took my object, right now, and made a copy of it, I'd have two instances that had a context of the report node.
Then, on the first instance, I could do an XPath evaluation of "/patient" and get the "Jones, Jon" node.
On the second instance, I could do an XPath evaluation of "/doctor" and get the "Mathews, Matt" node.
Without being able to somehow copy the context, the second instance would get "Trejo, Tony" when it did an XPath evaluation of "/doctor".
I could obviously try to keep using the same context, but then my instances would need to keep assigning _context->node to the node that they want XPath evaluations to be relative to. I suppose that's not too bad - but it seems like it would be better to let each instance have its own context. In order to make that work, I need to be able to copy the context.
I didn't invent the library that I'm translating. =) But, I do need to support its functionality. I am doing reference counting on the _doc, so that I know when to do xmlFreeDoc(_doc), so that shouldn't be a problem. I suspect that what I want to do is something like this, in my copy constructor :
_context = xmlXPathNewContext(_doc);
_context->node = previous_instance_context->node;
But my question is - is that sufficient? =)
> 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 clarify, I am not defining any functions or variables bound to the context. If I were, though - I would like the ability to copy them to a new context, as long as I could guarantee that the xmlDocPtr would still be valid for them. I don't believe the library I'm translating makes use of functions or variables bound to the context, though - so it's not an issue for me (unless some of the XPath functions define functions or variables bound to the context, without my realizing it).
I sincerely thank you for your attention and assistance.
-Matt