summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Stocker <chregu@php.net>2002-11-29 10:24:44 +0000
committerChristian Stocker <chregu@php.net>2002-11-29 10:24:44 +0000
commiteed5b11b5f34470b49800d3485bab8c5786dcbff (patch)
tree66ce271251227c8e3f8bd7f4d7d2ddbcdd05c8b1
parentb1dab292147e708d3a62fcc704f08eb1bf9bd630 (diff)
downloadphp-git-eed5b11b5f34470b49800d3485bab8c5786dcbff.tar.gz
do some kind of automatic namespace registration in xpath_eval(). This
works only for namespaces defined in the context node (eg docroot if no second argument is given. If one wants to use namespaces defined elsewhere or with different prefixes, you still have to use xpath_ns_register()
-rw-r--r--ext/domxml/php_domxml.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c
index 98cf75b2de..8a4e0179ac 100644
--- a/ext/domxml/php_domxml.c
+++ b/ext/domxml/php_domxml.c
@@ -4735,9 +4735,9 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
xmlXPathContextPtr ctxp;
xmlXPathObjectPtr xpathobjp;
xmlNode *contextnodep;
- int ret, str_len;
+ int ret, str_len, nsNr;
char *str;
-
+ xmlNsPtr *namespaces;
contextnode = NULL;
contextnodep = NULL;
@@ -4761,6 +4761,26 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
DOMXML_GET_OBJ(contextnodep, contextnode, le_domxmlnodep);
}
ctxp->node = contextnodep;
+
+ /* automatic namespace definitions registration.
+ it's only done for the context node
+ if you need namespaces defined in other nodes,
+ you have to specify them explicitely with
+ xpath_register_ns();
+ */
+ if (contextnodep) {
+ namespaces = xmlGetNsList(ctxp->doc, contextnodep);
+ } else {
+ namespaces = xmlGetNsList(ctxp->doc, xmlDocGetRootElement(ctxp->doc));
+ }
+
+ nsNr = 0;
+ if (namespaces != NULL) {
+ while (namespaces[nsNr] != NULL) {
+ xmlXPathRegisterNs(ctxp, namespaces[nsNr]->prefix, namespaces[nsNr]->href);
+ nsNr++;
+ }
+ }
#if defined(LIBXML_XPTR_ENABLED)
if (mode == PHP_XPTR) {
@@ -4884,20 +4904,25 @@ PHP_FUNCTION(xpath_register_ns)
int prefix_len, uri_len, result;
xmlXPathContextPtr ctxp;
- char *prefix, *uri, *uri_static;
+ char *prefix, *uri;
zval *id;
DOMXML_PARAM_FOUR(ctxp, id, le_xpathctxp, "ss", &prefix, &prefix_len, &uri, &uri_len);
- /* set the context node to NULL - what is a context node anyway? */
ctxp->node = NULL;
+ #ifdef CHREGU_0
+ /* this leads to memleaks... commenting it out, as it works for me without copying
+ it. chregu */
/*
this is a hack - libxml2 doesn't copy the URI, it simply uses the string
given in the parameter - which is normally deallocated after the function
*/
- uri_static = estrndup(uri, uri_len);
+ uri_static = estrndup(uri, uri_len);
result = xmlXPathRegisterNs(ctxp, prefix, uri_static);
+ #endif
+
+ result = xmlXPathRegisterNs(ctxp, prefix, uri);
if (0 == result) {
RETURN_TRUE;