0

我正在尝试学习 SharePoint 中 CAML 查询的基础知识。由于各种非技术原因,我目前仅限于使用 VBSCRIPT 将我的请求发送到我希望查询的站点。我能够连接到该站点并检索数据,但是目标列表中的所有行和所有列都将被返回,而不是请求的特定数据。关于我做错了什么以及如何解决问题的任何想法将不胜感激。这是代码:

dim soapEnv
dim oHttp
dim URL

set oHttp = CreateObject("Microsoft.XmlHttp")

URL     = "https://[MyCorporateSite]/_vti_bin/Lists.asmx?op=GetListItems"
soapEnv = "<?xml version='1.0' encoding='utf-8'?>" _
        & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" _
        &    "<soap:Body>" _
        &       "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" _    
        &          "<listName>{3C786148-E3E1-425B-84BE-6E44335D5645}</listName>" _
        &          "<Query>" _
        &             "<Where>" _
        &                "<Eq>" _
        &                   "<FieldRef Name='ApplicationID' />" _
        &                   "<Value Type='Text'>5Z4PWS</Value>" _
        &                 "</Eq>" _
        &             "</Where>" _
        &          "</Query>" _
        &          "<ViewFields xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" _
        &             "<FieldRef Name='ApplicationID' />" _
        &             "<FieldRef Name='ApplicationName' />" _
        &          "</ViewFields>" _
        &          "<RowLimit>1</RowLimit>" _
        &       "</GetListItems>" _
        &    "</soap:Body>" _
        & "</soap:Envelope>"

oHttp.Open "POST", URL, False, [MySiteUID], [MySitePWD]
oHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oHttp.send soapEnv
WScript.Echo oHttp.responseText

我知道我应该最终将结果分配给 XML 文档而不是回显返回文本,但我希望在担心演示文稿之前让查询正常工作。

此外,由于公司限制,无法下载 CAML 创建/格式化工具。

4

1 回答 1

0

找到了。这是修改后的代码:

dim soapEnv
dim oHttp
dim URL

set oHttp = CreateObject("Microsoft.XmlHttp")

URL     = "https://[MyCorporateSite]/_vti_bin/Lists.asmx?op=GetListItems"
soapEnv = "<?xml version='1.0' encoding='utf-8'?>" _
        & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" _
        &    "<soap:Body>" _
        &       "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" _
        &          "<listName>{3C786148-E3E1-425B-84BE-6E44335D5645}</listName>" _
        &          "<query>" _
        &             "<Query>" _
        &                "<Where>" _
        &                   "<Eq>" _
        &                      "<FieldRef Name='ApplicationID' />" _
        &                      "<Value Type='Text'>5Z4PWS</Value>" _
        &                    "</Eq>" _
        &                "</Where>" _
        &             "</Query>" _
        &          "</query>" _
        &          "<ViewFields>" _
        &             "<ViewFields xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" _
        &                "<FieldRef Name='ApplicationID' />" _
        &                "<FieldRef Name='ApplicationName' />" _
        &             "</ViewFields>" _
        &         "</ViewFields>" _
        &       "</GetListItems>" _
        &    "</soap:Body>" _
        & "</soap:Envelope>"

oHttp.Open "POST", URL, False, [MySiteUID], [MySitePWD]
oHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oHttp.send soapEnv
WScript.Echo oHttp.responseText

请注意附加的 Query 和 ViewFields 标记。

于 2013-06-20T14:44:26.087 回答