CAML查询以获取特定行
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CAML查询以获取特定行相关的知识,希望对你有一定的参考价值。
我使用Excel VBA使用SOAP请求获取SharePoint列表。
我能够获取所有记录。
如何获取具有特定卷号的名称?
以下是Excel VBA代码段。
Public Function retrieveSharepoint()
Dim currentId As String, ACP As String, DL As String
Dim returnedRow As Object
Dim setNode As Object
Dim sURL As String
Dim sEnv As String
Dim xmlhtp As New MSXML2.XMLHTTP60
Dim xmlDoc As New DOMDocument60
sURL = "https://sites.com/sites/project/project_ext/_vti_bin/lists.asmx"
sEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
sEnv = sEnv & "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://schemas.xmlsoap.org/soap/envelope/"">"
sEnv = sEnv & " <soap12:Body>"
sEnv = sEnv & " <GetListItems xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">"
sEnv = sEnv & " <listName>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}</listName>"
sEnv = sEnv & " </GetListItems>"
sEnv = sEnv & " </soap12:Body>"
sEnv = sEnv & "</soap12:Envelope>"
With xmlhtp
.Open "post", sURL, False
.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
.setRequestHeader "soapAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
.send sEnv
xmlDoc.LoadXML (.responseText)
For Each returnedRow In .responseXML.getElementsByTagName("z:row")
currentId = returnedRow.getAttribute("ows_Roll_x0020_Number")
ACP = returnedRow.getAttribute("ows_Name")
DL = returnedRow.getAttribute("ows_Last_x0020_Name")
Next
MsgBox .responseText
End With
End Function
目前我可以获取所有记录。
答案
只需使用Query
元素:
/编辑
好的,我已经检查过Postman,并且正确的SOAP XML就是例如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}</listName>
<query>
<Query>
<Where>
<Eq>
<FieldRef Name='ID' />
<Value Type='Number'>260</Value>
</Eq>
</Where>
</Query>
</query>
</GetListItems>
</soapenv:Body>
</soapenv:Envelope>
所以,你的代码应该是这样的:
sEnv = sEnv & " <listName>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}</listName>"
sEnv = sEnv & " <query><Query><Where><Eq><FieldRef Name='Roll_x0020_Number' /><Value Type='Number'>#YOUR NUMBER#</Value></Eq></Where></Query></query>"
补充参考:Lists.GetListItems
以上是关于CAML查询以获取特定行的主要内容,如果未能解决你的问题,请参考以下文章
SharePoint:如何使用列表中的 CAML 查询获取前 5 条记录
Sharepoint Online 突出显示的内容 Web 部件 - 显示文件子文件夹 CAML 查询