Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 如何将值节点上移为其父节点的属性?_Python_Soap_Suds - Fatal编程技术网

Python 如何将值节点上移为其父节点的属性?

Python 如何将值节点上移为其父节点的属性?,python,soap,suds,Python,Soap,Suds,我需要更改什么,以便FieldRef下的名称节点是FieldRef的属性,而不是子节点 Suds当前生成以下soap: <ns0:query> <ns0:Where> <ns0:Eq> <ns0:FieldRef> <ns0:Name>_ows_ID</ns0:Name> </ns0:FieldRef> <ns0:Value>66<

我需要更改什么,以便FieldRef下的名称节点是FieldRef的属性,而不是子节点

Suds当前生成以下soap:

<ns0:query>
  <ns0:Where>
    <ns0:Eq>
      <ns0:FieldRef>
        <ns0:Name>_ows_ID</ns0:Name>
      </ns0:FieldRef>
      <ns0:Value>66</ns0:Value>
    </ns0:Eq>
  </ns0:Where>
</ns0:query>
printq的结果是

(query){
   Where = 
      (Where){
         Eq = 
            (Eq){
               FieldRef = 
                  (FieldRef){
                     Name = "_ows_ID"
                  }
               Value = "66"
            }
      }
 }
下面是生成创建soap请求的WS-call的代码

c = client.Client(url='https://community.site.edu/_vti_bin/Lists.asmx?WSDL',
                  transport=WindowsHttpAuthenticated(username='domain\user',
                                                     password='password')
                                             )
ll= c.service.GetListItems(listName="{BD59F6D9-AB4B-474D-BCC7-E4B4BEA7EB27}",
                             viewName="{407A6AB9-97CF-4E1F-8544-7DD67CEA997B}",
                             query=q
                             )
包括文本XML

要包含文本而不是转义的XML 作为对象的参数值 属性,则需要设置该值 对象的参数 属性设置为sax元素。这个 marshaller被设计为 附加并附加已删除的内容 已经是XML了

例如,您希望通过 以下XML作为参数:

埃尔默·福德 33 瓦比特猎手

可以按以下方式进行操作:

from suds.sax.element import Element
query = Element('query')
name = Element('name').setText('Elmer Fudd')
age = Element('age').setText('33')
age.set('units', 'years')
job = Element('job').setText('Wabbit Hunter')
query.append(name)
query.append(age)
query.append(job)
client.service.runQuery(query)

那么问题到底是什么呢?你不能让第一个看起来像第二个吗?@Jack我需要做什么更改,以便FieldRef下的名称节点是FieldRef的属性,而不是子节点?
c = client.Client(url='https://community.site.edu/_vti_bin/Lists.asmx?WSDL',
                  transport=WindowsHttpAuthenticated(username='domain\user',
                                                     password='password')
                                             )
ll= c.service.GetListItems(listName="{BD59F6D9-AB4B-474D-BCC7-E4B4BEA7EB27}",
                             viewName="{407A6AB9-97CF-4E1F-8544-7DD67CEA997B}",
                             query=q
                             )
from suds.sax.element import Element
#create the nodes
q = Element('query')
where=Element('Where')
eq=Element('Eq')
fieldref=Element('FieldRef')
fieldref.set('Name', '_ows_ID')
value=Element('Value')
value.setText('66')

#append them
eq.append(fieldref)
eq.append(value)
where.append(eq)
q.append(where)
from suds.sax.element import Element
query = Element('query')
name = Element('name').setText('Elmer Fudd')
age = Element('age').setText('33')
age.set('units', 'years')
job = Element('job').setText('Wabbit Hunter')
query.append(name)
query.append(age)
query.append(job)
client.service.runQuery(query)