Python sud中的属性和值
我对wsdl中的complextype有一些问题。这里是wsdl的一部分:Python sud中的属性和值,python,wsdl,suds,Python,Wsdl,Suds,我对wsdl中的complextype有一些问题。这里是wsdl的一部分: <xs:element name="Params" nillable="true"> <xs:complexType> <xs:sequence>
<xs:element name="Params" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="Param" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
如果我设置_name,sud将生成XML:
<ns0:Params>
<ns0:Param name="name1"/>
<ns0:Param name="name2"/>
</ns0:Params>
因此,我可以为“Param”设置属性名称,但如何设置值?您必须创建没有属性的“Param”元素,然后使用封送插件添加“name”属性:
# disclaimer: not tested!
from suds.plugin import MessagePlugin
class MyPlugin(MessagePlugin):
def marshalled(self, context):
body = context.envelope.getChild('Body')
params = body.getChild('fix_this_path').getChild('Params')
foo = params[0]
foo.set('name', 'name1')
client = Client(url, plugins=[MyPlugin()])
...
params = client.factory.create("Payment.Params")
params.param = "val1"
更多信息请点击此处:
希望这对您有所帮助如果您设置名称
(不带下划线),您会得到什么XML?
<ns0:Params>
<ns0:Param name="name1"/>
<ns0:Param name="name2"/>
</ns0:Params>
# disclaimer: not tested!
from suds.plugin import MessagePlugin
class MyPlugin(MessagePlugin):
def marshalled(self, context):
body = context.envelope.getChild('Body')
params = body.getChild('fix_this_path').getChild('Params')
foo = params[0]
foo.set('name', 'name1')
client = Client(url, plugins=[MyPlugin()])
...
params = client.factory.create("Payment.Params")
params.param = "val1"