如何使Python字典看起来像下面的SOAP元素?

2024-05-16 10:38:45 发布

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

这是我试图创建的SOAP主体:

   <soapenv:Body>
      <sch:AddStuffRequest>
         <!--You may enter the following 4 items in any order-->
         <sch:someCheck>true</sch:someCheck>
         <sch:keyColumn>email</sch:keyColumn>
         <sch:overwrite>true</sch:overwrite>
         <sch:attributes>
            <!--Zero or more repetitions:-->
            <sch:item>
               <!--You may enter the following 2 items in any order-->
               <sch:key>email</sch:key>
               <sch:value>sample@sample.com</sch:value>
            </sch:item>
            <sch:item>
               <!--You may enter the following 2 items in any order-->
               <sch:key>gender</sch:key>
               <sch:value>0</sch:value>
            </sch:item>
            <sch:item>
               <!--You may enter the following 2 items in any order-->
               <sch:key>sometype</sch:key>
               <sch:value>0</sch:value>
            </sch:item>
            <sch:item>
               <!--You may enter the following 2 items in any order-->
               <sch:key>someName</sch:key>
               <sch:value>Peter</sch:value>
            </sch:item>
         </sch:attributes>
      </sch:AddSubscriberRequest>
   </soapenv:Body>

请注意sch:attributes元素。它们包含键:值对。我想使用Python字典来实现这一点。但是,还有一个额外的元素,即sch:item元素,如SOAP示例中所示

如何在python中创建这样的内容,使每个key:value对前面都有“item:”元素


Tags: thekeyinyou元素valueanyorder