cvs: php4 /ext/domxml php_domxml.c php_domxml.h
| From: | Chris Jarecki | Date: | Sun, 13 Jan 2002 01:17:34 +0000 |
| Subject: | cvs: php4 /ext/domxml php_domxml.c php_domxml.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-9049@lists.php.net to get a copy of this message | ||
zenderx Sat Jan 12 20:17:34 2002 EDT
Modified files:
/php4/ext/domxml php_domxml.h php_domxml.c
Log:
- 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)
Index: php4/ext/domxml/php_domxml.h
diff -u php4/ext/domxml/php_domxml.h:1.35 php4/ext/domxml/php_domxml.h:1.36
--- php4/ext/domxml/php_domxml.h:1.35 Fri Jan 11 16:15:46 2002
+++ php4/ext/domxml/php_domxml.h Sat Jan 12 20:17:34 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.h,v 1.35 2002/01/11 21:15:46 jarkol Exp $ */
+/* $Id: php_domxml.h,v 1.36 2002/01/13 01:17:34 zenderx Exp $ */
#ifndef PHP_DOMXML_H
#define PHP_DOMXML_H
@@ -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_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);
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.97 php4/ext/domxml/php_domxml.c:1.98
--- php4/ext/domxml/php_domxml.c:1.97 Fri Jan 11 16:15:46 2002
+++ php4/ext/domxml/php_domxml.c Sat Jan 12 20:17:34 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.97 2002/01/11 21:15:46 jarkol Exp $ */
+/* $Id: php_domxml.c,v 1.98 2002/01/13 01:17:34 zenderx Exp $ */
/* TODO
* - Support Notation Nodes
@@ -177,6 +177,7 @@
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_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}
};
@@ -3028,6 +3030,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) */