2011-07-27 52 views

回答

1

我通過SOAP使用CAML查詢,然後喂響應到XML解析器

可能需要一些微調,但是這將讓你大部分的方式存在。我使用類似的東西。

它可能看起來很複雜,但一切都很好,您只需將URL更改爲您的社區即可。

啓用'Debug.Print .responseText'和'debug.print .status來調試任何問題。狀態爲200意味着它找到了該站點。

function start_here() 

set user_list = get_users("http://sites.company.com/sites/00672") 

for each n in user_list 
    debug.print str(n), userlist(str(n)) 
next 

end function 

Function get_users(site_URL) 

Dim xmlDoc 
Set xmlDoc = CreateObject("Msxml2.DOMDocument") 

request = "<?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>" + _ 
       "<GetUserCollectionFromSite xmlns='http://schemas.microsoft.com/sharepoint/soap/directory/' />" + _ 
      "</soap:Body>" + _ 
     "</soap:Envelope>" 

    With CreateObject("Microsoft.XMLHTTP") 
     .Open "Get", site_URL & "/_vti_bin/usergroup.asmx", False, Null, Null 
     .setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
     .setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/directory/GetUserCollectionFromSite" 
     .send request 
     'Debug.Print .status 
     'Debug.Print .responseText 
     xmlDoc.LoadXML (.responseText) 
    End With 

Set nodesCollection = xmlDoc.SelectNodes("//Users/User") 
Set ID = xmlDoc.createNode(1, "xml", "") 
Set user_name = xmlDoc.createNode(1, "xml", "") 

Set user_col = New Collection 

    For Each nodeElement In nodesCollection 
     Set ID = nodeElement.Attributes.getNamedItem("ID") 
     Set user_name = nodeElement.Attributes.getNamedItem("Name") 
     user_col.Add user_name.Text), Str(ID.Text) 
    Next 

Set get_users = user_col 

end function 
相關問題