使用SUDS时添加xsi:type和信封命名空间

使用SUDS时添加xsi:type和信封命名空间,第1张

使用SUDS时添加xsi:type和信封命名空间

我发现的解决方案是使用MessagePlugin在发送前实质上手动修复XML。我希望有一些更优雅的东西,但这至少可以起作用

class SoapFixer(MessagePlugin):    def marshalled(self, context):        # Alter the envelope so that the xsd namespace is allowed        context.envelope.nsprefixes['xsd'] = 'http://www.w3.org/2001/XMLSchema'        # Go through every node in the document and apply the fix function to patch up incompatible XML.         context.envelope.walk(self.fix_any_type_string)    def fix_any_type_string(self, element):        """Used as a filter function with walk in order to fix errors.        If the element has a certain name, give it a xsi:type=xsd:string. Note that the nsprefix xsd must also         be added in to make this work."""        # Fix elements which have these names        fix_names = ['elementnametofix', 'anotherelementname']        if element.name in fix_names: element.attributes.append(Attribute('xsi:type', 'xsd:string'))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5601850.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存