pythonpython-3.xsoapspyne

Using spyne, trying to produce a specific SOAP response with a XML attribute and a string value in the same element


Using spyne to process and generate SOAP request/response. For a specific SOAP response, need to generate like

<SetSpecial tag="Monday">123</SetSpecial>
<SetSpecial tag="Tuesday">45</SetSpecial>

Could not get that exactly

Followed the tutorial of Spyne and also few almost similar posts, including Spyne custom XML response

Tried the below code......

class CustomModel(ComplexModel):
    Value = String
    tag = XmlAttribute(Unicode)

## Then in actual view
response = Response()
response.SetSpecial([CustomModel(Value="123", tag="Monday"), CustomModel(Value="45", tag="Tuesday")]) 

Apart from ComplexModel could not get hands on any simple spyne Model to produce both an XML attribute and the string/integer primitive value in the same element.

Above response is a small portion in a bigger response. All other portions were well defined using Spyne's Complex Model. Only the mentioned part is not coming in the desired way.

Please provide any inputs.


Solution

  • The following should work:

    class CustomModel(ComplexModel):
        Value = XmlData(Unicode)
        tag = XmlAttribute(Unicode)