您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

使用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'))
其他 2022/1/1 18:38:29 有352人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶