chregu Fri Nov 29 06:22:07 2002 EDT Modified files: /php4/ext/domxml php_domxml.c php_domxml.h Log: @- Added xpath_register_ns_auto([contextnode]) for automatically registering @ namespace definitions (chregu) changed my mind. Automatic namesapce registration is not done within xpath_eval() anymore, but in a seperate function. Index: php4/ext/domxml/php_domxml.c diff -u php4/ext/domxml/php_domxml.c:1.222 php4/ext/domxml/php_domxml.c:1.223 --- php4/ext/domxml/php_domxml.c:1.222 Fri Nov 29 05:24:44 2002 +++ php4/ext/domxml/php_domxml.c Fri Nov 29 06:22:06 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_domxml.c,v 1.222 2002/11/29 10:24:44 chregu Exp $ */ +/* $Id: php_domxml.c,v 1.223 2002/11/29 11:22:06 chregu Exp $ */ /* TODO * - Support Notation Nodes @@ -264,6 +264,7 @@ PHP_FE(xpath_eval, NULL) PHP_FE(xpath_eval_expression, NULL) PHP_FE(xpath_register_ns, NULL) + PHP_FE(xpath_register_ns_auto, + NULL) PHP_FE(domxml_doc_get_elements_by_tagname, NULL) #endif @@ -489,6 +490,7 @@ 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) + PHP_FALIAS(xpath_register_ns_auto, xpath_register_ns_auto, + NULL) {NULL, NULL, NULL} }; @@ -4737,7 +4739,6 @@ xmlNode *contextnodep; int ret, str_len, nsNr; char *str; - xmlNsPtr *namespaces; contextnode = NULL; contextnodep = NULL; @@ -4762,26 +4763,6 @@ } 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) { xpathobjp = xmlXPtrEval(BAD_CAST str, ctxp); @@ -4897,11 +4878,6 @@ Registeres the given namespace in the passed XPath context */ PHP_FUNCTION(xpath_register_ns) { - /* - TODO: - - automagically register all namespaces when creating a new context - */ - int prefix_len, uri_len, result; xmlXPathContextPtr ctxp; char *prefix, *uri; @@ -4930,6 +4906,45 @@ RETURN_FALSE; } /* }}} */ + +/* {{{ proto bool xpath_register_ns_auto([object xpathctx_handle,] [object +contextnode]) + Registeres the given namespace in the passed XPath context */ +PHP_FUNCTION(xpath_register_ns_auto) +{ + /* 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(); + */ + + zval *contextnode = NULL, *id; + xmlXPathContextPtr ctxp; + xmlNodePtr contextnodep; + xmlNsPtr *namespaces; + int nsNr; + + DOMXML_PARAM_ONE(ctxp, id, le_xpathctxp, "|o", &contextnode); + + if (contextnode == NULL) { + namespaces = xmlGetNsList(ctxp->doc, xmlDocGetRootElement(ctxp->doc)); + } else { + DOMXML_GET_OBJ(contextnodep, contextnode, le_domxmlnodep); + namespaces = xmlGetNsList(ctxp->doc, contextnodep); + } + + nsNr = 0; + if (namespaces != NULL) { + while (namespaces[nsNr] != NULL) { + xmlXPathRegisterNs(ctxp, namespaces[nsNr]->prefix, +namespaces[nsNr]->href); + nsNr++; + } + } + + RETURN_TRUE; +} +/* }}} */ + #endif /* defined(LIBXML_XPATH_ENABLED) */ #if defined(LIBXML_XPTR_ENABLED) Index: php4/ext/domxml/php_domxml.h diff -u php4/ext/domxml/php_domxml.h:1.72 php4/ext/domxml/php_domxml.h:1.73 --- php4/ext/domxml/php_domxml.h:1.72 Fri Aug 23 11:26:19 2002 +++ php4/ext/domxml/php_domxml.h Fri Nov 29 06:22:06 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_domxml.h,v 1.72 2002/08/23 15:26:19 chregu Exp $ */ +/* $Id: php_domxml.h,v 1.73 2002/11/29 11:22:06 chregu Exp $ */ #ifndef PHP_DOMXML_H #define PHP_DOMXML_H @@ -214,6 +214,7 @@ PHP_FUNCTION(xpath_eval); PHP_FUNCTION(xpath_eval_expression); PHP_FUNCTION(xpath_register_ns); +PHP_FUNCTION(xpath_register_ns_auto); PHP_FUNCTION(domxml_doc_get_elements_by_tagname); PHP_FUNCTION(domxml_doc_get_element_by_id); #endif
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php