[xml] Convert xmlXPathObjectPtr to xmlXPathContextPtr



libxml2 guys:

I have a xmlXPathObjectPtr, and I want a xmlXPathContextPtr, so I can pass
this to a subsequent call to 'xmlXPathEvalExpression(path, context)'.

Put another way, I want to use two XPaths; the second one evaluates within
the context that the first returns.

The XPath verbiage (specifically the O'Reilly book /XPath and XPointer/)
imply that XPath works by walking a context, from the top of a document with
all its nodes, down to specific nodes and thence specific leaves.

This makes me think that the "Parser Context" is an important object,
possibly the one represented by <xpathInternals.h> as
xmlXPathParserContextPtr.

If not, why does 'xmlXPathEvalExpression(path, context)' take a handle to a
"context", not a "parsed document"?

The source code for what I want would be:

    string xml ("<you><look>mawvelous</look></you>");
    xmlDocPtr document(xmlParseDoc(BAD_CAST xml.c_str()));
    xmlXPathContextPtr context(xmlXPathNewContext(document));

    xmlXPathObjectPtr res = xmlXPathEvalExpression(
                    BAD_CAST "/you", context);

    xmlXPathContextPtr nuContext = ??? (xmlXPathObjectPtr);

    xmlXPathObjectPtr nuRes = xmlXPathEvalExpression(
                    BAD_CAST "/look", nuContext);

    ASSERT_EQUAL(string ("mawvelous",
        (char*)xmlXPathCastToString(nuRes));

If I can't do that, can something convert the first path to an unambiguous
string, so I can attach this to the second? I don't want to convert by
myself, because I'm ambiguous.

--
  Phlip
        http://clublet.com/c/c/why?ZenoBuddhism
  --  My opinions are those of your employer  --

(BTW: Yippee! gmane has made the mailing list interface non-heinous!!!)






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