在 vba 中解析对 xml 对象的 Web 请求响应时获取类型不匹配

发布于 2025-01-16 20:33:55 字数 1341 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2025-01-23 20:33:55

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 like WebRequest.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文