<p>对于手头的任务,我找到了部分问题的解决方案——我正在使用<code>suds.plugin.MessagePlugin</code>实现来清除savewebservice响应负载,并防止suds将其解析为DOM。这是我最初问题中的第2项:</p>
<blockquote>
<p>avoid running suds.sax.parser and do not build DOM object containing
whole response tree</p>
</blockquote>
<p>下面是在公共Web服务中使用这种方法的示例。在</p>
<p>查看<a href="https://gist.github.com/smartkiwi/5153378#file-suds_prevent_parsing" rel="nofollow">gist</a>中的完整代码</p>
<pre><code> import suds
class PayloadInterceptor(suds.plugin.MessagePlugin):
def __init__(self, *args, **kwargs):
self.last_payload = None
def received(self, context):
#recieved xml as a string
print "%s bytes received" % len(context.reply)
self.last_payload = context.reply
#clean up reply to prevent parsing
context.reply = ""
return context
if __name__=='__main__':
wsurl = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL"
payload_interceptor = PayloadInterceptor()
client = suds.client.Client(wsurl, plugins=[payload_interceptor])
print client
res = client.service.CapitalCity("NL")
print "received %s bytes" % len(payload_interceptor.last_payload)
print "parsed result: %s" % res
print "response payload: %s" % payload_interceptor.last_payload
</code></pre>
<p>产出:</p>
^{pr2}$