Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sud中的属性和值_Python_Wsdl_Suds - Fatal编程技术网

Python sud中的属性和值

Python sud中的属性和值,python,wsdl,suds,Python,Wsdl,Suds,我对wsdl中的complextype有一些问题。这里是wsdl的一部分: <xs:element name="Params" nillable="true"> <xs:complexType> <xs:sequence>

我对wsdl中的complextype有一些问题。这里是wsdl的一部分:

<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"