I have the following xml from part of an auto generated web service wsdl:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="test">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element name="txt" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="test2">
<xs:complexType>
<xs:sequence>
<xs:element name="txt" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="request_box">
<xs:complexType>
<xs:all minOccurs="0">
<xs:element ref="ns0:test"/>
<xs:element ref="ns0:test2"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
when I do a soap call from php:
$xml = "test.xml";
$params = array(
'test' => array(
'txt' => $txt
)
);
try {
$client = new SoapClient($xml);
$test = $client->request_box($params);
} catch (SoapFault $fault) {
var_dump($fault);
}
I get this error:
SOAP-ERROR: Encoding: object has no 'test2' property
If I change $params
and add test2
to it then I dont get any erros:
$params = array(
'test' => array(
'txt' => $txt
),
'test2' => array(
'txt' => $txt
)
);
But I want test2
to be optional.
If I change xml and add minOccurs="0"
to test2
the problem will be solved and I dont get any errors anymore:
<xs:element name="request_box">
<xs:complexType>
<xs:all minOccurs="0">
<xs:element ref="ns0:test"/>
<xs:element ref="ns0:test2" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
But should't all the child elements (here test
and test2
) already inherit minOccurs="0"
from the parent <xs:all minOccurs="0">
?