0

这是一些 Spyne/SOAP 代码,我在其中返回一两个字符串。有没有办法避免必须将 string2 设置为 None 以表明它不存在?

class TestResult(ComplexModel):
    """
    """
    string1 = Unicode
    string2 = Unicode(min_occurs=0, max_occurs=1)

    def __init__(self):
        # Say hello
        self.string1 = "Hello World"

        # Either of the following works
        #
        # self.string2 = "...from Paul"
        # self.string2 = None
        #
        # But omitting them doesn't.


class Test(ServiceBase):
    """
    """
    @srpc(Unicode, _returns=TestResult)
    def Test(Query):
        """
        """
        response = TestResult()

        return response
4

2 回答 2

0

我真的不明白这个问题,请澄清。

string2xsi:null如果min_occurs=1这就是您所要求的,将显式返回。

于 2015-07-16T09:02:20.667 回答
0

string2 is optional (min_occurs=0) but I have to explicitly set it to 'None' to have it omitted completely from the XML response. I am asking is there something that I'm missing that would allow me to have the code as written (i.e. string2 never explicitly set) and generate a valid response. The background is that I'm having to support some XML where responses have large numbers of optional fields but I'm having to set a long list of them tom NULL - so I'm hoping I can be lazy and find a way to avoid having to do this ;-).

于 2015-07-17T09:31:55.220 回答