【问题标题】:How do I set XML attributes in SOAPpy with python?如何使用 python 在 SOAPpy 中设置 XML 属性?
【发布时间】:2010-08-10 01:14:31
【问题描述】:

我正在形成一个 SOAPpy 请求,但我不知道如何在标签中设置属性。这是我的代码:

url = wsdlfile = 'https://stats2.overture.com/ExternalSOAP/statsPMCAPI_1_0.wsdl'
n = 'urn:yahoo:overture:stats:3.0'
server = WSDL.Proxy(wsdlfile)
server.soapproxy.config.dumpSOAPOut = 1
server.soapproxy.config.dumpSOAPIn = 1
result = server.getAvailablePmcReports(ReportAuth = {'username': username, 'cookie': YBY}, ReportRequest= '')
print(result)

哪个输出这个:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getAvailablePmcReports xmlns:ns1="urn:yahoo:overture:stats:3.0" SOAP-ENC:root="1">
<ReportRequest xsi:type="xsd:string"></ReportRequest>
<ReportAuth>
<username xsi:type="xsd:string">myuser</username>
<cookie xsi:type="xsd:string">cookie here...</cookie>
</ReportAuth>
</ns1:getAvailablePmcReports>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但我想要的是这样的:

<ReportRequest startRow="0" shownRows="200">

如何添加属性? 谢谢。

【问题讨论】:

  • 能否请您提供完整的源 XML 文档以及您希望从中形成的最终 XML 文档?我也许能帮上忙。

标签: python soappy


【解决方案1】:

您可以通过为 ReportRequest 关键字参数传递一个类型化的值来做到这一点。例如,如果我将getAvailablePmcReports 行更改为:

from SOAPpy import Types
result = server.getAvailablePmcReports(
    ReportAuth = {'username': username, 'cookie': YBY},
    ReportRequest= Types.stringType('', attrs={'startRow': 0, 'shownRows': 200}))

生成的请求包含这样的标签:

<ReportRequest xsi:type="xsd:string" shownRows="200" startRow="0"></ReportRequest>

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2023-03-05
    • 2013-06-17
    • 2018-08-30
    • 1970-01-01
    • 2019-09-20
    • 2011-04-25
    • 2010-12-21
    • 1970-01-01
    相关资源
    最近更新 更多