Suds generates empty elements; how to remove them?

前端 未结 7 1520
傲寒
傲寒 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:48

    There's an even easier way - no need for any Reg Ex or exciting iterators ;)

    First, define the plugin:

    class PrunePlugin(MessagePlugin):
        def marshalled(self, context):
            context.envelope = context.envelope.prune()
    

    Then use it when creating the client:

    client = Client(url, plugins=[PrunePlugin()])
    

    The prune() method will remove any empty nodes, as documented here: http://jortel.fedorapeople.org/suds/doc/suds.sax.element.Element-class.html

提交回复
热议问题