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

发布于 2024-07-24 09:06:47 字数 1834 浏览 6 评论 0原文

我需要更改什么才能使 FieldRef 下的 Name 节点成为 FieldRef 的属性,而不是子节点?

Suds 当前生成以下肥皂:

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

我需要的是:

<ns0:query>
  <ns0:Where>
     <ns0:Eq>
        <ns0:FieldRef Name="_ows_ID">
        </ns0:FieldRef>
        <ns0:Value>66</ns0:Value>
     </ns0:Eq>
  </ns0:Where>
</ns0:query>

第一个 xml 结构由 suds 从以下代码生成。

q = c.factory.create('GetListItems.query')
q['Where']=InstFactory.object('Where')
q['Where']['Eq']=InstFactory.object('Eq')
q['Where']['Eq']['FieldRef']=InstFactory.object('FieldRef')
q['Where']['Eq']['FieldRef'].Name='_ows_ID'
q['Where']['Eq']['Value']='66'

print(q) 结果如下:

(query){
   Where = 
      (Where){
         Eq = 
            (Eq){
               FieldRef = 
                  (FieldRef){
                     Name = "_ows_ID"
                  }
               Value = "66"
            }
      }
 }

这是进行创建肥皂请求的 WS 调用的代码

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
                             )

What do I need to change so the Name node under FieldRef is an attribute of FieldRef, and not a child node?

Suds currently generates the following 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>

What I need is this:

<ns0:query>
  <ns0:Where>
     <ns0:Eq>
        <ns0:FieldRef Name="_ows_ID">
        </ns0:FieldRef>
        <ns0:Value>66</ns0:Value>
     </ns0:Eq>
  </ns0:Where>
</ns0:query>

The first xml structure is generated by suds from the below code.

q = c.factory.create('GetListItems.query')
q['Where']=InstFactory.object('Where')
q['Where']['Eq']=InstFactory.object('Eq')
q['Where']['Eq']['FieldRef']=InstFactory.object('FieldRef')
q['Where']['Eq']['FieldRef'].Name='_ows_ID'
q['Where']['Eq']['Value']='66'

and print(q) results in

(query){
   Where = 
      (Where){
         Eq = 
            (Eq){
               FieldRef = 
                  (FieldRef){
                     Name = "_ows_ID"
                  }
               Value = "66"
            }
      }
 }

Here's the code that makes the WS call that creates the soap request

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
                             )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯到世界奔溃 2024-07-31 09:06:47
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)

https://fedorahosted.org/suds/wiki/TipsAndTricks

包括文字 XML

包含文字(未转义)XML
作为对象的参数值
属性,需要设置值
对象的参数
属性是一个 sax 元素。 这
marshaller 的设计目的很简单
附加并附加内容
已经是 XML。

例如,您想要传递
以下 XML 作为参数:

<代码><查询>; <名称>埃尔默·福德
<年龄单位=“年”>33
<工作>兔子猎人

可以按如下方式完成:

from suds.sax.element import Element 
  查询 = 元素('查询') 
  name = Element('name').setText('Elmer Fudd') 
  年龄 = Element('年龄').setText('33') 
  年龄.set('单位', '年') 
  job = Element('job').setText('兔子猎人') 
  查询.追加(名称) 
  查询.append(年龄) 
  查询.追加(作业) 
  client.service.runQuery(查询) 
  
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)

https://fedorahosted.org/suds/wiki/TipsAndTricks

Including Literal XML

To include literal (not escaped) XML
as a parameter value of object
attribute, you need to set the value
of the parameter of the object
attribute to be a sax Element. The
marshaller is designed to simply
attach and append content that is
already XML.

For example, you want to pass the
following XML as a parameter:

<query> <name>Elmer Fudd</name>
<age unit="years">33</age>
<job>Wabbit Hunter</job> </query>

The can be done as follows:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文