在 vba 中解析对 xml 对象的 Web 请求响应时获取类型不匹配
在 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
I am getting a type mismatch (run timer error 13) for when parsing a web request response to an xml object in VBA.
The error is on this line: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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
loadXML 方法正在等待一个字符串。您没有向我们展示
WebRequest
背后的确切对象是什么,但看起来WebRequest.responseXML
可能返回一个对象。在同一文档中,建议您可以通过执行以下操作来获取字符串形式的正文:
xmldoc.LoadXML WebRequest.responseXML.xml
The loadXML Method is expecting a String. You don't show us what the exact object behind
WebRequest
is but it looks likeWebRequest.responseXML
might return an object.From that same document it is suggested you can get the body as a string by doing this:
xmldoc.LoadXML WebRequest.responseXML.xml