泡沫中的属性和值

2024-06-16 09:55:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我对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>

SOAP req中的结果字段必须类似于:

^{pr2}$

肥皂水给我下一种类型:

>>> client.factory.create("Payment.Params.Param")  
(Param){  
    _name = ""  
}

如果我设置了\u name,suds会生成XML:

<ns0:Params>
    <ns0:Param name="name1"/>
    <ns0:Param name="name2"/>
</ns0:Params>

所以,我可以为“Param”设置属性名,但是如何设置值呢?在


Tags: nametruestringparamextensionelementparamswsdl
1条回答
网友
1楼 · 发布于 2024-06-16 09:55:47

必须创建不带属性的“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"

更多信息:https://fedorahosted.org/suds/wiki/Documentation#MessagePlugin

希望这有帮助

相关问题 更多 >