From: Chris Jarecki Date: Sun, 13 Jan 2002 01:17:34 +0000 (+0000) Subject: - Added xpath_register_ns() function. X-Git-Tag: PRE_ISSET_PATCH~206 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65362872674b312e1dee4bb7d0c922a851c81a37;p=php - Added xpath_register_ns() function. @ - Added xpath_register_ns() function. @ It makes possible to issue XPath queries with namespaces @ like for example: "//namespace:sampletag" (Chris Jarecki) --- diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 910065da29..6e93d7586c 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -177,6 +177,7 @@ static zend_function_entry domxml_functions[] = { PHP_FE(xpath_new_context, NULL) PHP_FE(xpath_eval, NULL) PHP_FE(xpath_eval_expression, NULL) + PHP_FE(xpath_register_ns, NULL) #endif #if defined(LIBXML_XPTR_ENABLED) PHP_FE(xptr_new_context, NULL) @@ -336,6 +337,7 @@ static zend_function_entry php_domxmlpi_class_functions[] = { static zend_function_entry php_xpathctx_class_functions[] = { PHP_FALIAS(xpath_eval, xpath_eval, NULL) PHP_FALIAS(xpath_eval_expression, xpath_eval_expression, NULL) + PHP_FALIAS(xpath_register_ns, xpath_register_ns, NULL) {NULL, NULL, NULL} }; @@ -3030,6 +3032,49 @@ PHP_FUNCTION(xpath_eval_expression) php_xpathptr_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_XPATH, 1); } /* }}} */ + +/* {{{ proto bool xpath_register_ns([int xpathctx_handle,] string namespace_prefix, string namespace_uri) + Registeres the given namespace in the passed XPath context */ +PHP_FUNCTION(xpath_register_ns) +{ + /* + TODO: + - make the namespace registration persistent - now it dissapears each time xpath_eval is called + - automagically register all namespaces when creating a new context + */ + int prefix_len, uri_len, result; + xmlXPathContextPtr ctxp; + char *prefix, *uri; + zval *id; + + if (NULL == (id = getThis())) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oss", &id, &prefix, &prefix_len, &uri, &uri_len) == FAILURE) { + return; + } + } else { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &prefix_len, &uri, &uri_len) == FAILURE) { + return; + } + } + + ctxp = php_xpath_get_context(id, le_xpathctxp, 0 TSRMLS_CC); + if (!ctxp) { + php_error(E_WARNING, "%s(): cannot fetch XPATH context", get_active_function_name(TSRMLS_C)); + RETURN_FALSE; + } + + /* set the context node to NULL - what is a context node anyway? */ + ctxp->node = NULL; + + result = xmlXPathRegisterNs(ctxp, prefix, uri); + + if (0 == result) { + RETURN_TRUE; + } + + RETURN_FALSE; +} +/* }}} */ #endif /* defined(LIBXML_XPATH_ENABLED) */ #if defined(LIBXML_XPTR_ENABLED) diff --git a/ext/domxml/php_domxml.h b/ext/domxml/php_domxml.h index be669a5f09..4028188171 100644 --- a/ext/domxml/php_domxml.h +++ b/ext/domxml/php_domxml.h @@ -31,6 +31,7 @@ #endif #if defined(LIBXML_XPATH_ENABLED) #include +#include #endif #if defined(LIBXML_XPTR_ENABLED) #include @@ -155,6 +156,7 @@ PHP_FUNCTION(xpath_init); PHP_FUNCTION(xpath_new_context); PHP_FUNCTION(xpath_eval); PHP_FUNCTION(xpath_eval_expression); +PHP_FUNCTION(xpath_register_ns); #endif #if defined(LIBXML_XPTR_ENABLED) PHP_FUNCTION(xptr_new_context);