2017-06-16 95 views
0

我有以下Python代碼來設置首標用於SOAP請求:如何使用zeep添加wsu:Id屬性?

ebsheader = xsd.Element(
    '{http://ebs.health.ontario.ca/}EBS', 
    xsd.ComplexType([ 
     xsd.Attribute(
      'Id',xsd.String() 
     ), 
     xsd.Element(
      'SoftwareConformanceKey', xsd.String() 
     ), 
     xsd.Element(
      'AuditId', xsd.String() 
     ), 
    ]) 
) 
headers = [] 
headers.append(ebsheader('id-1','software-key-here','unique-id')) 

它產生下面的XML:

<ns0:EBS xmlns:ns0="http://ebs.health.ontario.ca/" Id="id-1"> 
    <SoftwareConformanceKey>software-key-here</SoftwareConformanceKey> 
    <AuditId>unique-id</AuditId> 
</ns0:EBS> 

然而,代替Id="id-1"我需要它是wsu:Id="id-1"。我需要在標題中指定哪個參數來完成此操作?

回答

1

你需要傳遞一個命名空間,因此,例如

xsd.Attribute(
     '{http://my-namespace}Id',xsd.String() 
    ), 
+0

當我這樣做,我得到這樣的結果:''我對xml相當陌生,它是說'ns0:Id = ...'而不是'wsu:Id = ...'很重要嗎? – andrei

+0

結果應該是一樣的,ns0/wsu只是全名空間的簡寫 – mvantellingen