Xml 向Zeep中的元素添加可选属性
我正在尝试使用Zeep调用Workday SOAP服务 我能够成功调用服务,添加元素以过滤请求,并获得响应,但我需要在请求元素中指定版本属性,我无法确定如何添加它:Xml 向Zeep中的元素添加可选属性,xml,soap,zeep,workday-api,Xml,Soap,Zeep,Workday Api,我正在尝试使用Zeep调用Workday SOAP服务 我能够成功调用服务,添加元素以过滤请求,并获得响应,但我需要在请求元素中指定版本属性,我无法确定如何添加它: service = client.create_service( '{urn:com.workday/bsvc/'+Human_Resources+'}'+Human_Resources+'Binding', 'http://my-endpoint.com') service_operation =
service = client.create_service(
'{urn:com.workday/bsvc/'+Human_Resources+'}'+Human_Resources+'Binding',
'http://my-endpoint.com')
service_operation = 'Get_Job_Profiles'
request_filter = {'Response_Filter' : {
'Page': 1,
'Count' : 100, }}
#other things are added to the request_filter dict as well
response = getattr(service,service_operation)(**request_filter)
这个很好用。Zeep生产:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<ns0:Workday_Common_Header xmlns:ns0="urn:com.workday/bsvc">
<ns0:Include_Reference_Descriptors_In_Response>true</ns0:Include_Reference_Descriptors_In_Response>
</ns0:Workday_Common_Header>
# some other security related headers here #
</soap-env:Header>
<soap-env:Body xmlns:ns0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ns0:Id="id-3b0aa2ca-dc0f-417c-9168-498275645b16">
<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc">
<ns0:Request_Criteria>
<ns0:Transaction_Log_Criteria_Data>
<ns0:Transaction_Date_Range_Data>
<ns0:Updated_From>2000-01-01T00:00:00</ns0:Updated_From>
<ns0:Updated_Through>2018-05-09T00:00:00</ns0:Updated_Through>
</ns0:Transaction_Date_Range_Data>
</ns0:Transaction_Log_Criteria_Data>
</ns0:Request_Criteria>
<ns0:Response_Filter>
<ns0:As_Of_Entry_DateTime>2018-05-09T00:00:00</ns0:As_Of_Entry_DateTime>
<ns0:Page>2</ns0:Page>
<ns0:Count>100</ns0:Count>
</ns0:Response_Filter>
<ns0:Response_Group>
<ns0:Include_Reference>true</ns0:Include_Reference>
<ns0:Include_Job_Profile_Basic_Data>true</ns0:Include_Job_Profile_Basic_Data>
<ns0:Include_Job_Classification_Data>true</ns0:Include_Job_Classification_Data>
<ns0:Include_Workers_Compensation_Data>true</ns0:Include_Workers_Compensation_Data>
<ns0:Include_Job_Profile_Compensation_Data>true</ns0:Include_Job_Profile_Compensation_Data>
</ns0:Response_Group>
</ns0:Get_Job_Profiles_Request>
</soap-env:Body>
</soap-env:Envelope>
真的
#这里还有一些其他与安全相关的头#
2000-01-01T00:00:00
2018-05-09T00:00:00
2018-05-09T00:00:00
2.
100
真的
真的
真的
真的
真的
但现在我需要添加一个属性:
<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc">
它需要看起来像这样:
<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc" ns0:version="v29">
以下是xsd中的定义:
<xsd:complexType name="Get_Job_Profiles_RequestType">
<xsd:annotation>
<xsd:documentation>Request element used to find and get Job Profiles and their associated data.</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="Request_References" type="wd:Job_Profile_Request_ReferencesType" minOccurs="0"/>
<xsd:element name="Request_Criteria" type="wd:Job_Profile_Request_CriteriaType" minOccurs="0"/>
<xsd:element name="Response_Filter" type="wd:Response_FilterType" minOccurs="0"/>
<xsd:element name="Response_Group" type="wd:Job_Profile_Response_GroupType" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute ref="wd:version"/></xsd:complexType>
用于查找和获取作业配置文件及其关联数据的请求元素。
添加一个元素和一个值很容易,但如何向元素添加属性却难倒了我 Zeep很聪明,我所需要做的就是将它添加为kwarg: 之前:
response = getattr(service,service_operation)(**request_filter)
之后:
response = getattr(service,service_operation)(**request_filter, version='v29.1')
从而产生:
<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc" ns0:version="v29.1">