Suds generates empty elements; how to remove them?

前端 未结 7 1657
傲寒
傲寒 2020-12-31 07:51

[Major Edit based on experience since 1st post two days ago.]

I am building a Python SOAP/XML script using Suds, but am struggling to get the code to generate SOAP/X

7条回答
  •  情书的邮戳
    2020-12-31 08:52

    I thought I'd share a pretty simple update on the solution above that should work for any WSDL: Note that the sending method is not necessary - it's so that you can audit your changes, as the Client's debug request printing fires before the marshal method runs.

    class XMLBS_Plugin(MessagePlugin):
    def marshalled(self, context):
        def w(x):
            if x.isempty():
                print "EMPTY: ", x
                x.detach()
    
        context.envelope.walk(w)
    
    def sending(self,context):
        c = copy.deepcopy(context.envelope)
        c=c.replace('><','>\n<') # some sort of readability
        logging.info("SENDING: \n%s"%c)
    

提交回复
热议问题