获取对 vba 中 xml 对象的类型不匹配解析 Web 请求响应
Getting a type mismatch parsing web request response to xml object in vba
我在解析对 VBA 中的 xml 对象的 Web 请求响应时遇到类型不匹配(运行 计时器错误 13)。
错误在这一行:
xmldoc.LoadXML WebRequest.responseXML
WebRequest.Open "POST", urlRef, False
WebRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
WebRequest.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetURLSegments"
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> " & _
" <GetURLSegments xmlns='http://schemas.microsoft.com/sharepoint/soap/'> " & _
" <strURL>" & strDocUrl & "</strURL>" & _
" </GetURLSegments>" & _
" </soap12:Body> " & _
"</soap12:Envelope>"
WebRequest.send strRequest
Dim xmldoc As Object
Set xmldoc = CreateObject("Msxml2.DOMDocument.6.0")
xmldoc.SetProperty "SelectionLanguage", "XPath"
xmldoc.LoadXML WebRequest.responseXML
For Each xmlnode In xmldoc.SelectNodes("//*[contains(name(),'strItemID')]")
Debug.Print xmlnode.Text
Next
loadXML Method is expecting a String. You don't show us what the exact object behind WebRequest
is but it looks like WebRequest.responseXML
might return an object.
在同一文档中,建议您可以通过执行以下操作将正文作为字符串获取:
xmldoc.LoadXML WebRequest.responseXML.xml
我在解析对 VBA 中的 xml 对象的 Web 请求响应时遇到类型不匹配(运行 计时器错误 13)。
错误在这一行:
xmldoc.LoadXML WebRequest.responseXML
WebRequest.Open "POST", urlRef, False
WebRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
WebRequest.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetURLSegments"
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> " & _
" <GetURLSegments xmlns='http://schemas.microsoft.com/sharepoint/soap/'> " & _
" <strURL>" & strDocUrl & "</strURL>" & _
" </GetURLSegments>" & _
" </soap12:Body> " & _
"</soap12:Envelope>"
WebRequest.send strRequest
Dim xmldoc As Object
Set xmldoc = CreateObject("Msxml2.DOMDocument.6.0")
xmldoc.SetProperty "SelectionLanguage", "XPath"
xmldoc.LoadXML WebRequest.responseXML
For Each xmlnode In xmldoc.SelectNodes("//*[contains(name(),'strItemID')]")
Debug.Print xmlnode.Text
Next
loadXML Method is expecting a String. You don't show us what the exact object behind WebRequest
is but it looks like WebRequest.responseXML
might return an object.
在同一文档中,建议您可以通过执行以下操作将正文作为字符串获取:
xmldoc.LoadXML WebRequest.responseXML.xml