* xmlXPathEval: * @str: the XPath expression * @ctx: the XPath context * * Evaluate the XPath Location Path in the given context. * * Returns the xmlXPathObjectPtr resulting from the evaluation or NULL. * the caller has to free the object. */
| 13285 | * the caller has to free the object. |
| 13286 | */ |
| 13287 | xmlXPathObjectPtr |
| 13288 | xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) { |
| 13289 | xmlXPathParserContextPtr ctxt; |
| 13290 | xmlXPathObjectPtr res; |
| 13291 | |
| 13292 | if (ctx == NULL) |
| 13293 | return(NULL); |
| 13294 | |
| 13295 | xmlInitParser(); |
| 13296 | |
| 13297 | xmlResetError(&ctx->lastError); |
| 13298 | |
| 13299 | ctxt = xmlXPathNewParserContext(str, ctx); |
| 13300 | if (ctxt == NULL) |
| 13301 | return NULL; |
| 13302 | xmlXPathEvalExpr(ctxt); |
| 13303 | |
| 13304 | if (ctxt->error != XPATH_EXPRESSION_OK) { |
| 13305 | res = NULL; |
| 13306 | } else if (ctxt->valueNr != 1) { |
| 13307 | xmlXPathErr(ctxt, XPATH_STACK_ERROR); |
| 13308 | res = NULL; |
| 13309 | } else { |
| 13310 | res = valuePop(ctxt); |
| 13311 | } |
| 13312 | |
| 13313 | xmlXPathFreeParserContext(ctxt); |
| 13314 | return(res); |
| 13315 | } |
| 13316 | |
| 13317 | /** |
| 13318 | * xmlXPathSetContextNode: |
no test coverage detected