[xml] xmlXPathEval() redundant?



People,
I was looking for the difference between xmlXPathEval() and xmlXPathEvalExpression() and am puzzled!

These 2 are effectively identical..here's the diff..
Anybody in the know?


--
Wai-Sun "Squidster" Chia
Unix/Web Developer/RHCE
Professional Services
--- foo Fri Jul 20 00:01:23 2001
+++ bar Fri Jul 20 00:01:46 2001
@@ -1,45 +1,55 @@
-**
- * xmlXPathEvalExpression:
+/**
+ * xmlXPathEval:
  * @str:  the XPath expression
- * @ctxt:  the XPath context
+ * @ctx:  the XPath context
  *
- * Evaluate the XPath expression in the given context.
+ * Evaluate the XPath Location Path in the given context.
  *
- * Returns the xmlXPathObjectPtr resulting from the evaluation or NULL.
+ * Returns the xmlXPathObjectPtr resulting from the eveluation or NULL.
  *         the caller has to free the object.
  */
 xmlXPathObjectPtr
-xmlXPathEvalExpression(const xmlChar *str, xmlXPathContextPtr ctxt) {
-    xmlXPathParserContextPtr pctxt;
-    xmlXPathObjectPtr res, tmp;
+xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) {
+    xmlXPathParserContextPtr ctxt;
+    xmlXPathObjectPtr res, tmp, init = NULL;
     int stack = 0;
 
     xmlXPathInit();
 
-    CHECK_CONTEXT(ctxt)
+    CHECK_CONTEXT(ctx)
 
-    pctxt = xmlXPathNewParserContext(str, ctxt);
-    xmlXPathEvalExpr(pctxt);
+    ctxt = xmlXPathNewParserContext(str, ctx);
+    xmlXPathEvalExpr(ctxt);
 
-    if (*pctxt->cur != 0) {
-       xmlXPatherror(pctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
+    if (ctxt->value == NULL) {
+       xmlGenericError(xmlGenericErrorContext,
+               "xmlXPathEval: evaluation failed\n");
+       res = NULL;
+    } else if (*ctxt->cur != 0) {
+       xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
        res = NULL;
     } else {
-       res = valuePop(pctxt);
+       res = valuePop(ctxt);
     }
+
     do {
-        tmp = valuePop(pctxt);
+        tmp = valuePop(ctxt);
        if (tmp != NULL) {
-           xmlXPathFreeObject(tmp);
+           if (tmp != init)
            stack++;
+           xmlXPathFreeObject(tmp);
        }
     } while (tmp != NULL);
     if ((stack != 0) && (res != NULL)) {
        xmlGenericError(xmlGenericErrorContext,
-               "xmlXPathEvalExpression: %d object left on the stack\n",
+               "xmlXPathEval: %d object left on the stack\n",
                stack);
     }
-    xmlXPathFreeParserContext(pctxt);
+    if (ctxt->error != XPATH_EXPRESSION_OK) {
+       xmlXPathFreeObject(res);
+       res = NULL;
+    }
+
+    xmlXPathFreeParserContext(ctxt);
     return(res);
 }
-


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