]> granicus.if.org Git - php/commitdiff
- Added xpath_register_ns() function.
authorChris Jarecki <zenderx@php.net>
Sun, 13 Jan 2002 01:17:34 +0000 (01:17 +0000)
committerChris Jarecki <zenderx@php.net>
Sun, 13 Jan 2002 01:17:34 +0000 (01:17 +0000)
@ - Added xpath_register_ns() function.
@   It makes possible to issue XPath queries with namespaces
@   like for example: "//namespace:sampletag" (Chris Jarecki)

ext/domxml/php_domxml.c
ext/domxml/php_domxml.h

index 910065da29c5a32eb72551ad674859fa02a4524b..6e93d7586c472ca2bc72f0fd56a20cedfefe6b8e 100644 (file)
@@ -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)
index be669a5f09ceae22f55dc8bf58c02094554fb128..4028188171a3a8ee52fb2652c5b04f14a2f02287 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 #if defined(LIBXML_XPATH_ENABLED)
 #include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
 #endif
 #if defined(LIBXML_XPTR_ENABLED)
 #include <libxml/xpointer.h>
@@ -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);