@@ -4735,9 +4735,9 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
4735
4735
xmlXPathContextPtr ctxp ;
4736
4736
xmlXPathObjectPtr xpathobjp ;
4737
4737
xmlNode * contextnodep ;
4738
- int ret , str_len ;
4738
+ int ret , str_len , nsNr ;
4739
4739
char * str ;
4740
-
4740
+ xmlNsPtr * namespaces ;
4741
4741
contextnode = NULL ;
4742
4742
contextnodep = NULL ;
4743
4743
@@ -4761,6 +4761,26 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
4761
4761
DOMXML_GET_OBJ (contextnodep , contextnode , le_domxmlnodep );
4762
4762
}
4763
4763
ctxp -> node = contextnodep ;
4764
+
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
+ }
4764
4784
4765
4785
#if defined(LIBXML_XPTR_ENABLED )
4766
4786
if (mode == PHP_XPTR ) {
@@ -4884,20 +4904,25 @@ PHP_FUNCTION(xpath_register_ns)
4884
4904
4885
4905
int prefix_len , uri_len , result ;
4886
4906
xmlXPathContextPtr ctxp ;
4887
- char * prefix , * uri , * uri_static ;
4907
+ char * prefix , * uri ;
4888
4908
zval * id ;
4889
4909
4890
4910
DOMXML_PARAM_FOUR (ctxp , id , le_xpathctxp , "ss" , & prefix , & prefix_len , & uri , & uri_len );
4891
4911
4892
- /* set the context node to NULL - what is a context node anyway? */
4893
4912
ctxp -> node = NULL ;
4894
4913
4914
+ #ifdef CHREGU_0
4915
+ /* this leads to memleaks... commenting it out, as it works for me without copying
4916
+ it. chregu */
4895
4917
/*
4896
4918
this is a hack - libxml2 doesn't copy the URI, it simply uses the string
4897
4919
given in the parameter - which is normally deallocated after the function
4898
4920
*/
4899
- uri_static = estrndup (uri , uri_len );
4921
+ uri_static = estrndup (uri , uri_len );
4900
4922
result = xmlXPathRegisterNs (ctxp , prefix , uri_static );
4923
+ #endif
4924
+
4925
+ result = xmlXPathRegisterNs (ctxp , prefix , uri );
4901
4926
4902
4927
if (0 == result ) {
4903
4928
RETURN_TRUE ;
0 commit comments