I'm using zeep
to handle some SOAP requests in Python and I've come across a situation for which I couldn't find any documentation (neither here, on SO, or their official docs).
First of, I created a factory
:
factory = client.type_factory('ns0')
Some of the attributes of this factory
looks like this:
In [76]: factory.IctAdditionalInfos()
Out[76]:
{
'item': []
}
Inside the item
I can have the following data:
In [79]: factory.IctAdditionalInfos(item={})
Out[79]:
{
'item': {
'PersonId': None,
'PersonIdExt': None,
'Sex': None,
'FirstName': None,
'LastName': None,
'Telephone': None,
'MobilePhone': None,
'Fax': None,
'Email': None
}
}
Now, what I want to happen, and I couldn't get my head around, is:
when trying to build and return the XML instead of sending it to the server using
client.create_message(service, wsdl_interface_name, **self.data)
(self.data
contains IctAdditionalInfos
) and when factory.IctAdditionalInfos
doesn't contain any data in item
, I'd like to get:
<IctAdditionalInfos></IctAdditionalInfos>
or
<IctAdditionalInfos/>
Instead of the above I get:
<IctAdditionalInfos>
<item/>
</IctAdditionalInfos>
because item
is mandatory.
The wsdl definition of IctIncidentAdditionalInfos
looks like this:
<xsd:complexType name="IctIncidentAdditionalInfos">
<xsd:sequence>
<xsd:element name="item" type="IctIncidentAdditionalInfo" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
How can I achieve this behaviour using zeep
?