[PHP-CVS] cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests profile12.phpt
helly Fri Apr 14 14:07:51 2006 UTC Added files: /php-src/ext/simplexml/testsprofile12.phpt Modified files: /php-src/ext/simplexml simplexml.c Log: - Allow access to namespaced root by specifying prefix on creation - Fix access to non namespaced root http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.204r2=1.205diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.204 php-src/ext/simplexml/simplexml.c:1.205 --- php-src/ext/simplexml/simplexml.c:1.204 Fri Apr 14 12:18:15 2006 +++ php-src/ext/simplexml/simplexml.c Fri Apr 14 14:07:51 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: simplexml.c,v 1.204 2006/04/14 12:18:15 helly Exp $ */ +/* $Id: simplexml.c,v 1.205 2006/04/14 14:07:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -69,7 +69,7 @@ if (name) { subnode-iter.name = xmlStrdup(name); } - if (prefix) { + if (prefix *prefix) { subnode-iter.nsprefix = xmlStrdup(prefix); } @@ -122,7 +122,7 @@ return 1; } - if (node-ns !xmlStrcmp(node-ns-href, name)) { + if (node-ns (/*!xmlStrcmp(node-ns-prefix, name) ||*/ !xmlStrcmp(node-ns-href, name))) { return 1; } @@ -1816,7 +1816,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options [, string ns]]]) Load a filename and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_file) { @@ -1824,12 +1824,12 @@ char *filename; int filename_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, filename, filename_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, filename, filename_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1848,6 +1848,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); + sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1856,7 +1857,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options [, string ns]]]) Load a string and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_string) { @@ -1864,12 +1865,12 @@ char *data; int data_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, data, data_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, data, data_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1888,6 +1889,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); + sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1897,19 +1899,19 @@ /* }}} */ -/* {{{ proto SimpleXMLElement::__construct(string data [, int options [, bool data_is_url]]) +/* {{{ proto SimpleXMLElement::__construct(string data [, int options [, bool data_is_url [, string ns]]]) SimpleXMLElement constructor */ SXE_METHOD(__construct) { php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - char *data; - int data_len; + char *data, *ns = NULL; + int data_len, *ns_len = 0; xmlDocPtr docp; longoptions = 0; zend_bool is_url = 0;
Re: [PHP-CVS] cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests profile12.phpt
Hi Marcus, I think it would be better to speficy namespace URI rather than prefix. Prefix can be anything, so unless you know what was used, you need to use the new namespace methods (which are primarily debug functions). It is more common to known the URI than prefix. I havent tried the changes yet, but is it required to specify the namespace for a document element in a namespace or when loading does it automatically set the namespace scope based on the namespace of the doc element? Rob Marcus Boerger wrote: helly Fri Apr 14 14:07:51 2006 UTC Added files: /php-src/ext/simplexml/tests profile12.phpt Modified files: /php-src/ext/simplexml simplexml.c Log: - Allow access to namespaced root by specifying prefix on creation - Fix access to non namespaced root http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.204r2=1.205diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.204 php-src/ext/simplexml/simplexml.c:1.205 --- php-src/ext/simplexml/simplexml.c:1.204 Fri Apr 14 12:18:15 2006 +++ php-src/ext/simplexml/simplexml.c Fri Apr 14 14:07:51 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: simplexml.c,v 1.204 2006/04/14 12:18:15 helly Exp $ */ +/* $Id: simplexml.c,v 1.205 2006/04/14 14:07:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -69,7 +69,7 @@ if (name) { subnode-iter.name = xmlStrdup(name); } - if (prefix) { + if (prefix *prefix) { subnode-iter.nsprefix = xmlStrdup(prefix); } @@ -122,7 +122,7 @@ return 1; } - if (node-ns !xmlStrcmp(node-ns-href, name)) { + if (node-ns (/*!xmlStrcmp(node-ns-prefix, name) ||*/ !xmlStrcmp(node-ns-href, name))) { return 1; } @@ -1816,7 +1816,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options [, string ns]]]) Load a filename and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_file) { @@ -1824,12 +1824,12 @@ char *filename; int filename_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, filename, filename_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, filename, filename_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1848,6 +1848,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); + sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1856,7 +1857,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options [, string ns]]]) Load a string and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_string) { @@ -1864,12 +1865,12 @@ char *data; int data_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, data, data_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, data, data_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1888,6 +1889,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); + sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1897,19 +1899,19 @@ /* }}} */ -/* {{{ proto SimpleXMLElement::__construct(string data [, int options [, bool data_is_url]]) +/* {{{ proto
Re: [PHP-CVS] cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests profile12.phpt
I think using namespace URI will also help us out with default namespaces because they don't have a ns prefix. -adam On Fri, 14 Apr 2006, Rob Richards wrote: Hi Marcus, I think it would be better to speficy namespace URI rather than prefix. Prefix can be anything, so unless you know what was used, you need to use the new namespace methods (which are primarily debug functions). It is more common to known the URI than prefix. I havent tried the changes yet, but is it required to specify the namespace for a document element in a namespace or when loading does it automatically set the namespace scope based on the namespace of the doc element? Rob Marcus Boerger wrote: hellyFri Apr 14 14:07:51 2006 UTC Added files: /php-src/ext/simplexml/tests profile12.phpt Modified files: /php-src/ext/simplexml simplexml.c Log: - Allow access to namespaced root by specifying prefix on creation - Fix access to non namespaced root http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.204r2=1.205diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.204 php-src/ext/simplexml/simplexml.c:1.205 --- php-src/ext/simplexml/simplexml.c:1.204 Fri Apr 14 12:18:15 2006 +++ php-src/ext/simplexml/simplexml.cFri Apr 14 14:07:51 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: simplexml.c,v 1.204 2006/04/14 12:18:15 helly Exp $ */ +/* $Id: simplexml.c,v 1.205 2006/04/14 14:07:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -69,7 +69,7 @@ if (name) { subnode-iter.name = xmlStrdup(name); } -if (prefix) { +if (prefix *prefix) { subnode-iter.nsprefix = xmlStrdup(prefix); } @@ -122,7 +122,7 @@ return 1; } -if (node-ns !xmlStrcmp(node-ns-href, name)) { +if (node-ns (/*!xmlStrcmp(node-ns-prefix, name) ||*/ !xmlStrcmp(node-ns-href, name))) { return 1; } @@ -1816,7 +1816,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options [, string ns]]]) Load a filename and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_file) { @@ -1824,12 +1824,12 @@ char *filename; int filename_len; xmlDocPtr docp; -char *classname = ; -int classname_len = 0; +char *classname = NULL, *ns = NULL; +int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; -if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, filename, filename_len, classname, classname_len, options) == FAILURE) { +if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, filename, filename_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1848,6 +1848,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); +sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1856,7 +1857,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options [, string ns]]]) Load a string and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_string) { @@ -1864,12 +1865,12 @@ char *data; int data_len; xmlDocPtr docp; -char *classname = ; -int classname_len = 0; +char *classname = NULL, *ns = NULL; +int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; -if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, data, data_len, classname, classname_len, options) == FAILURE) { +if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, data, data_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1888,6 +1889,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); +sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1897,19
Re: [PHP-CVS] cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests profile12.phpt
Hello Rob, actually the comment was wrong/premature. This part of todays changes only allows the URI to be specified. The prefix stuff comes later. And well the prefix stuff is only a convenient stuff if you know what you do. And yes you are right only the URI is unique but not all people know this or even use XML in that manner. best regards marcus Friday, April 14, 2006, 5:44:44 PM, you wrote: Hi Marcus, I think it would be better to speficy namespace URI rather than prefix. Prefix can be anything, so unless you know what was used, you need to use the new namespace methods (which are primarily debug functions). It is more common to known the URI than prefix. I havent tried the changes yet, but is it required to specify the namespace for a document element in a namespace or when loading does it automatically set the namespace scope based on the namespace of the doc element? Rob Marcus Boerger wrote: helly Fri Apr 14 14:07:51 2006 UTC Added files: /php-src/ext/simplexml/tests profile12.phpt Modified files: /php-src/ext/simplexml simplexml.c Log: - Allow access to namespaced root by specifying prefix on creation - Fix access to non namespaced root http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.204r2=1.205diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.204 php-src/ext/simplexml/simplexml.c:1.205 --- php-src/ext/simplexml/simplexml.c:1.204Fri Apr 14 12:18:15 2006 +++ php-src/ext/simplexml/simplexml.c Fri Apr 14 14:07:51 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: simplexml.c,v 1.204 2006/04/14 12:18:15 helly Exp $ */ +/* $Id: simplexml.c,v 1.205 2006/04/14 14:07:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -69,7 +69,7 @@ if (name) { subnode-iter.name = xmlStrdup(name); } - if (prefix) { + if (prefix *prefix) { subnode-iter.nsprefix = xmlStrdup(prefix); } @@ -122,7 +122,7 @@ return 1; } - if (node-ns !xmlStrcmp(node-ns-href, name)) { + if (node-ns (/*!xmlStrcmp(node-ns-prefix, name) ||*/ !xmlStrcmp(node-ns-href, name))) { return 1; } @@ -1816,7 +1816,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_file(string filename [, string class_name [, int options [, string ns]]]) Load a filename and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_file) { @@ -1824,12 +1824,12 @@ char *filename; int filename_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, filename, filename_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, filename, filename_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1848,6 +1848,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); + sxe-iter.nsprefix = ns_len ? xmlStrdup(ns) : NULL; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC); php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC); @@ -1856,7 +1857,7 @@ } /* }}} */ -/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options]]) +/* {{{ proto simplemxml_element simplexml_load_string(string data [, string class_name [, int options [, string ns]]]) Load a string and return a simplexml_element object to allow for processing */ PHP_FUNCTION(simplexml_load_string) { @@ -1864,12 +1865,12 @@ char *data; int data_len; xmlDocPtr docp; - char *classname = ; - int classname_len = 0; + char *classname = NULL, *ns = NULL; + int classname_len = 0, ns_len = 0; longoptions = 0; zend_class_entry *ce= sxe_class_entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sl, data, data_len, classname, classname_len, options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|sls, data, data_len, classname, classname_len, options, ns, ns_len) == FAILURE) { return; } @@ -1888,6 +1889,7 @@ } sxe = php_sxe_object_new(ce TSRMLS_CC); +