]> granicus.if.org Git - php/commitdiff
support for XMLSchema <element> nillable attribute
authorDmitry Stogov <dmitry@php.net>
Tue, 17 Feb 2004 15:10:16 +0000 (15:10 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 17 Feb 2004 15:10:16 +0000 (15:10 +0000)
ext/soap/php_encoding.c
ext/soap/php_schema.c
ext/soap/php_sdl.c
ext/soap/soap.c

index 69bf69a4b1865826d5b8cd55c5b364e958ded58b..4a16e8ee06305ffdb0790b1697aedb731e912bca 100644 (file)
@@ -108,7 +108,7 @@ static void set_ns_and_type(xmlNodePtr node, encodeTypePtr type);
        if (!zval || Z_TYPE_P(zval) == IS_NULL) { \
          if (style == SOAP_ENCODED) {\
                        xmlSetProp(xml, "xsi:nil", "1"); \
-               }\
+               } \
                return xml; \
        } \
 }
@@ -979,12 +979,34 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, HashTa
 
                                        zend_hash_internal_pointer_reset(ht);
                                        while (zend_hash_get_current_data(ht,(void**)&val) == SUCCESS) {
-                                               property = master_to_xml(enc, *val, style, node);
+                                               if (Z_TYPE_PP(val) == IS_NULL && model->u.element->nillable) {
+                                                       property = xmlNewNode(NULL,"BOGUS");
+                                                       xmlAddChild(node, property);
+                                                       if (style == SOAP_ENCODED) {
+                                                               xmlSetProp(property, "xsi:nil", "1");
+                                                       } else {
+                                                         xmlNsPtr xsi = encode_add_ns(property,XSI_NAMESPACE);
+                                                               xmlSetNsProp(property, xsi, "nil", "1");
+                                                       }
+                                               } else {
+                                                       property = master_to_xml(enc, *val, style, node);
+                                               }
                                                xmlNodeSetName(property, model->u.element->name);
                                                zend_hash_move_forward(ht);
                                        }
                                } else {
-                                       property = master_to_xml(enc, *data, style, node);
+                                       if (Z_TYPE_PP(data) == IS_NULL && model->u.element->nillable) {
+                                               property = xmlNewNode(NULL,"BOGUS");
+                                               xmlAddChild(node, property);
+                                               if (style == SOAP_ENCODED) {
+                                                       xmlSetProp(property, "xsi:nil", "1");
+                                               } else {
+                                                 xmlNsPtr xsi = encode_add_ns(property,XSI_NAMESPACE);
+                                                       xmlSetNsProp(property, xsi, "nil", "1");
+                                               }
+                                       } else {
+                                               property = master_to_xml(enc, *data, style, node);
+                                       }
                                        xmlNodeSetName(property, model->u.element->name);
                                }
                                return 1;
@@ -1149,7 +1171,19 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
 
                                zend_hash_internal_pointer_reset(prop);
                                while (zend_hash_get_current_data(prop,(void**)&val) == SUCCESS) {
-                                       xmlNodePtr property = master_to_xml(array_el->encode, *val, style, xmlParam);
+                                       xmlNodePtr property;
+                                       if (Z_TYPE_PP(val) == IS_NULL && array_el->nillable) {
+                                               property = xmlNewNode(NULL,"BOGUS");
+                                               xmlAddChild(xmlParam, property);
+                                               if (style == SOAP_ENCODED) {
+                                                       xmlSetProp(property, "xsi:nil", "1");
+                                               } else {
+                                                 xmlNsPtr xsi = encode_add_ns(property,XSI_NAMESPACE);
+                                                       xmlSetNsProp(property, xsi, "nil", "1");
+                                               }
+                                       } else {
+                                               property = master_to_xml(array_el->encode, *val, style, xmlParam);
+                                       }
                                        xmlNodeSetName(property, array_el->name);
                                        zend_hash_move_forward(prop);
                                }
index 6918cc7492cc6f3818ae5985850198cc9e19a228..34bf786f1df241908c1ed27614837951566a21e7 100644 (file)
@@ -2135,6 +2135,9 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type)
                        if (zend_hash_find(ctx->sdl->elements, type->ref, strlen(type->ref)+1, (void**)&tmp) == SUCCESS) {
                                type->encode = (*tmp)->encode;
                                /* TODO: nillable */
+                               if ((*tmp)->nillable) {
+                                 type->nillable = 1;
+                               }
                        } else {
                                php_error(E_ERROR, "SOAP-ERROR: Parsing Schema: unresolved element 'ref' attribute");
                        }
index e9d7246f3372eaff806625b36a21d7e5ada0a2c1..3993758f152139e2044f97c14c508966b86e8be3 100644 (file)
@@ -877,7 +877,7 @@ static sdlPtr load_wsdl(char *struri)
        return ctx.sdl;
 }
 
-#define WSDL_CACHE_VERSION 02
+#define WSDL_CACHE_VERSION 03
 
 #define WSDL_CACHE_GET(ret,type,buf)   memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type);
 #define WSDL_CACHE_GET_INT(ret,buf)    ret = ((int)(*buf)[0])|((int)(*buf)[1]<<8)|((int)(*buf)[2]<<16)|((int)(*buf)[3]<<24); *buf += 4;
@@ -992,14 +992,12 @@ static sdlContentModelPtr sdl_deserialize_model(sdlTypePtr *types, sdlTypePtr *e
                case XSD_CONTENT_ALL:
                case XSD_CONTENT_CHOICE:
                        WSDL_CACHE_GET_INT(i, in);
-                       if (i > 0) {
-                               model->u.content = emalloc(sizeof(HashTable));
-                               zend_hash_init(model->u.content, i, NULL, delete_model, 0);
-                               while (i > 0) {
-                                       sdlContentModelPtr x = sdl_deserialize_model(types, elements, in);
-                                       zend_hash_next_index_insert(model->u.content,&x,sizeof(sdlContentModelPtr),NULL);
-                                       i--;
-                               }
+                       model->u.content = emalloc(sizeof(HashTable));
+                       zend_hash_init(model->u.content, i, NULL, delete_model, 0);
+                       while (i > 0) {
+                               sdlContentModelPtr x = sdl_deserialize_model(types, elements, in);
+                               zend_hash_next_index_insert(model->u.content,&x,sizeof(sdlContentModelPtr),NULL);
+                               i--;
                        }
                        break;
                case XSD_CONTENT_GROUP_REF:
index 8802ba219382986e5f6061b7ee6d3e093d706225..5ab8a3687ede5ba8e95e85dce94e7ed52e100519 100644 (file)
@@ -387,6 +387,7 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals)
        /* hash by namespace */
        zend_hash_add(&soap_globals->defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
        zend_hash_add(&soap_globals->defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE), XSD_NS_PREFIX, sizeof(XSD_NS_PREFIX), NULL);
+       zend_hash_add(&soap_globals->defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE), XSI_NS_PREFIX, sizeof(XSI_NS_PREFIX), NULL);
        zend_hash_add(&soap_globals->defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE), SOAP_1_1_ENC_NS_PREFIX, sizeof(SOAP_1_1_ENC_NS_PREFIX), NULL);
        zend_hash_add(&soap_globals->defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE), SOAP_1_2_ENC_NS_PREFIX, sizeof(SOAP_1_2_ENC_NS_PREFIX), NULL);