@@ -264,6 +264,7 @@ static zend_function_entry domxml_functions[] = {
264
264
PHP_FE (xpath_eval , NULL )
265
265
PHP_FE (xpath_eval_expression , NULL )
266
266
PHP_FE (xpath_register_ns , NULL )
267
+ PHP_FE (xpath_register_ns_auto , NULL )
267
268
PHP_FE (domxml_doc_get_elements_by_tagname , NULL )
268
269
#endif
269
270
@@ -489,6 +490,7 @@ static zend_function_entry php_xpathctx_class_functions[] = {
489
490
PHP_FALIAS (xpath_eval , xpath_eval , NULL )
490
491
PHP_FALIAS (xpath_eval_expression , xpath_eval_expression , NULL )
491
492
PHP_FALIAS (xpath_register_ns , xpath_register_ns , NULL )
493
+ PHP_FALIAS (xpath_register_ns_auto , xpath_register_ns_auto , NULL )
492
494
{NULL , NULL , NULL }
493
495
};
494
496
@@ -4737,7 +4739,6 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
4737
4739
xmlNode * contextnodep ;
4738
4740
int ret , str_len , nsNr ;
4739
4741
char * str ;
4740
- xmlNsPtr * namespaces ;
4741
4742
contextnode = NULL ;
4742
4743
contextnodep = NULL ;
4743
4744
@@ -4762,26 +4763,6 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
4762
4763
}
4763
4764
ctxp -> node = contextnodep ;
4764
4765
4765
- /* automatic namespace definitions registration.
4766
- it's only done for the context node
4767
- if you need namespaces defined in other nodes,
4768
- you have to specify them explicitely with
4769
- xpath_register_ns();
4770
- */
4771
- if (contextnodep ) {
4772
- namespaces = xmlGetNsList (ctxp -> doc , contextnodep );
4773
- } else {
4774
- namespaces = xmlGetNsList (ctxp -> doc , xmlDocGetRootElement (ctxp -> doc ));
4775
- }
4776
-
4777
- nsNr = 0 ;
4778
- if (namespaces != NULL ) {
4779
- while (namespaces [nsNr ] != NULL ) {
4780
- xmlXPathRegisterNs (ctxp , namespaces [nsNr ]-> prefix , namespaces [nsNr ]-> href );
4781
- nsNr ++ ;
4782
- }
4783
- }
4784
-
4785
4766
#if defined(LIBXML_XPTR_ENABLED )
4786
4767
if (mode == PHP_XPTR ) {
4787
4768
xpathobjp = xmlXPtrEval (BAD_CAST str , ctxp );
@@ -4897,11 +4878,6 @@ PHP_FUNCTION(xpath_eval_expression)
4897
4878
Registeres the given namespace in the passed XPath context */
4898
4879
PHP_FUNCTION (xpath_register_ns )
4899
4880
{
4900
- /*
4901
- TODO:
4902
- - automagically register all namespaces when creating a new context
4903
- */
4904
-
4905
4881
int prefix_len , uri_len , result ;
4906
4882
xmlXPathContextPtr ctxp ;
4907
4883
char * prefix , * uri ;
@@ -4930,6 +4906,45 @@ PHP_FUNCTION(xpath_register_ns)
4930
4906
RETURN_FALSE ;
4931
4907
}
4932
4908
/* }}} */
4909
+
4910
+ /* {{{ proto bool xpath_register_ns_auto([object xpathctx_handle,] [object contextnode])
4911
+ Registeres the given namespace in the passed XPath context */
4912
+ PHP_FUNCTION (xpath_register_ns_auto )
4913
+ {
4914
+ /* automatic namespace definitions registration.
4915
+ it's only done for the context node
4916
+ if you need namespaces defined in other nodes,
4917
+ you have to specify them explicitely with
4918
+ xpath_register_ns();
4919
+ */
4920
+
4921
+ zval * contextnode = NULL , * id ;
4922
+ xmlXPathContextPtr ctxp ;
4923
+ xmlNodePtr contextnodep ;
4924
+ xmlNsPtr * namespaces ;
4925
+ int nsNr ;
4926
+
4927
+ DOMXML_PARAM_ONE (ctxp , id , le_xpathctxp , "|o" , & contextnode );
4928
+
4929
+ if (contextnode == NULL ) {
4930
+ namespaces = xmlGetNsList (ctxp -> doc , xmlDocGetRootElement (ctxp -> doc ));
4931
+ } else {
4932
+ DOMXML_GET_OBJ (contextnodep , contextnode , le_domxmlnodep );
4933
+ namespaces = xmlGetNsList (ctxp -> doc , contextnodep );
4934
+ }
4935
+
4936
+ nsNr = 0 ;
4937
+ if (namespaces != NULL ) {
4938
+ while (namespaces [nsNr ] != NULL ) {
4939
+ xmlXPathRegisterNs (ctxp , namespaces [nsNr ]-> prefix , namespaces [nsNr ]-> href );
4940
+ nsNr ++ ;
4941
+ }
4942
+ }
4943
+
4944
+ RETURN_TRUE ;
4945
+ }
4946
+ /* }}} */
4947
+
4933
4948
#endif /* defined(LIBXML_XPATH_ENABLED) */
4934
4949
4935
4950
#if defined(LIBXML_XPTR_ENABLED )
0 commit comments