2014-01-07 36 views
0

我只需要最後一步。也許這很愚蠢,但是..我在這裏錯過了什麼?我正在嘗試獲取SharePoint網站的所有列表。如果我調試我可以看到當地人窗格正確的樹,但的SelectNodes(「// _ SLIST」)沒有返回的孩子的......pure vba SiteData.GetListCollection在Excel 2010中使用

Sub MyTest() 
Const urlRef As String = "http://MySite/_vti_bin/SiteData.asmx" 
Dim WebRequest As New XMLHTTP60, strRequest As String 
WebRequest.Open "POST", urlRef, False 
WebRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
WebRequest.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListCollection" 
strRequest = _ 
    "<?xml version='1.0' encoding='utf-8'?> " & _ 
    "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'> " & _ 
    " <soap12:Body> " & _ 
    " <GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/' /> " & _ 
    " </soap12:Body> " & _ 
    "</soap12:Envelope>" 

WebRequest.send strRequest 

Dim docResponse As New DOMDocument60 
Set docResponse = WebRequest.responseXML 

docResponse.setProperty "SelectionLanguage", "XPath" 
Debug.Print docResponse.SelectNodes("//_sList").Length ' >>> Returns 0!!!! 
End Sub 
+0

嘗試添加默認名稱空間:http://support.microsoft.com/kb/313372 –

+0

我知道它!!!。謝謝。 – LeTapia

回答

0

下面是更正後的代碼...

Sub MyTest() 
Const urlRef As String = "http://MySite/_vti_bin/SiteData.asmx" 
Dim WebRequest As New XMLHTTP60, strRequest As String 
WebRequest.Open "POST", urlRef, False 
WebRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
WebRequest.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListCollection" 
strRequest = _ 
    "<?xml version='1.0' encoding='utf-8'?> " & _ 
    "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'> " & _ 
    " <soap12:Body> " & _ 
    " <GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/' /> " & _ 
    " </soap12:Body> " & _ 
    "</soap12:Envelope>" 

WebRequest.send strRequest 

Dim docResponse As New DOMDocument60 
Set docResponse = WebRequest.responseXML 
docResponse.setProperty "SelectionNamespaces", "xmlns:x='http://schemas.microsoft.com/sharepoint/soap/'" 

Debug.Print docResponse.SelectNodes("//x:_sList").Length ' >>> Now it Works!! 
End Sub