diff options
-rw-r--r-- | ext/simplexml/simplexml.c | 31 | ||||
-rwxr-xr-x | ext/simplexml/tests/profile12.phpt | 97 |
2 files changed, 114 insertions, 14 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 133b61e991..6651f7a296 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -69,7 +69,7 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE if (name) { subnode->iter.name = xmlStrdup(name); } - if (prefix) { + if (prefix && *prefix) { subnode->iter.nsprefix = xmlStrdup(prefix); } @@ -122,7 +122,7 @@ static inline int match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name) 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 @@ sxe_object_new(zend_class_entry *ce TSRMLS_DC) } /* }}} */ -/* {{{ 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 @@ PHP_FUNCTION(simplexml_load_file) 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; long options = 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 @@ PHP_FUNCTION(simplexml_load_file) } 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 @@ PHP_FUNCTION(simplexml_load_file) } /* }}} */ -/* {{{ 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 @@ PHP_FUNCTION(simplexml_load_string) 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; long options = 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 @@ PHP_FUNCTION(simplexml_load_string) } 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 @@ PHP_FUNCTION(simplexml_load_string) /* }}} */ -/* {{{ 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; long options = 0; zend_bool is_url = 0; php_set_error_handling(EH_THROW, zend_exception_get_default(TSRMLS_C) TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &data, &data_len, &options, &is_url) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lbs", &data, &data_len, &options, &is_url, &ns, &ns_len) == FAILURE) { php_std_error_handling(); return; } @@ -1924,6 +1926,7 @@ SXE_METHOD(__construct) return; } + 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); } diff --git a/ext/simplexml/tests/profile12.phpt b/ext/simplexml/tests/profile12.phpt new file mode 100755 index 0000000000..108574de5b --- /dev/null +++ b/ext/simplexml/tests/profile12.phpt @@ -0,0 +1,97 @@ +--TEST-- +SimpleXML [profile]: Accessing namespaced root and non namespaced children +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope +xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +xmlns:xsd="http://www.w3.org/2001/XMLSchema" +> +<soap:Body> +<businessList foo="bar"> +<businessInfo businessKey="bla"/> +</businessList> +</soap:Body> +</soap:Envelope> +EOF; + +$sxe = simplexml_load_string($xml, NULL, 0, 'soap'); +$nsl = $sxe->getNamespaces(); +var_dump($nsl); + +$sxe = simplexml_load_string($xml, NULL, 0, $nsl['soap']); +var_dump($sxe->Body); +var_dump($sxe->Body->children('')); +var_dump($sxe->Body->children('')->businessList); + +?> +===DONE=== +--EXPECTF-- +array(1) { + ["soap"]=> + string(41) "http://schemas.xmlsoap.org/soap/envelope/" +} +object(SimpleXMLElement)#%d (0) { +} +object(SimpleXMLElement)#%d (1) { + ["businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } +} +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } +} +===DONE=== +--UEXPECTF-- +array(1) { + [u"soap"]=> + string(41) "http://schemas.xmlsoap.org/soap/envelope/" +} +object(SimpleXMLElement)#%d (0) { +} +object(SimpleXMLElement)#%d (1) { + [u"businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + [u"@attributes"]=> + array(1) { + [u"businessKey"]=> + unicode(3) "bla" + } + } +} +object(SimpleXMLElement)#%d (2) { + [u"@attributes"]=> + array(1) { + [u"foo"]=> + unicode(3) "bar" + } + [u"businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + [u"@attributes"]=> + array(1) { + [u"businessKey"]=> + unicode(3) "bla" + } + } +} +===DONE=== |