我发现的解决方案是使用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'))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)