选择SingleNode failing with Soap Response VB6

选择SingleNode failing with Soap Response VB6,soap,vb6,Soap,Vb6,我已经在许多其他项目中使用了相同的代码,并且没有任何问题,但是出于某种原因,它在这里不起作用。每次我到达“If Not.selectSingleNode(strNode)Is Nothing Then”时,它都会返回空值,并将我放到else。我已经能够验证返回的XML(它列在下面)以及读取它的代码块 不幸的是,为了保持与其他产品的兼容性,我不得不在VB6中开发这个 代码如下: With objXMLResponse Dim strNode As String strNode =

我已经在许多其他项目中使用了相同的代码,并且没有任何问题,但是出于某种原因,它在这里不起作用。每次我到达“If Not.selectSingleNode(strNode)Is Nothing Then”时,它都会返回空值,并将我放到else。我已经能够验证返回的XML(它列在下面)以及读取它的代码块

不幸的是,为了保持与其他产品的兼容性,我不得不在VB6中开发这个

代码如下:

With objXMLResponse
    Dim strNode As String
    strNode = "//PingResponse/PingResult/ResultCode"
    If Not .selectSingleNode(strNode) Is Nothing Then
        If .selectSingleNode(strNode).Text = "Success" Then
            MsgBox "We have succeded", vbOKOnly
        Else
            MsgBox "We have failed", vbOKOnly
        End If
    Else
        MsgBox "We have failed", vbOKOnly
    End If
End With
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <PingResponse xmlns="http://avatax.avalara.com/services">
         <PingResult>
            <TransactionId>784293066</TransactionId>
            <ResultCode>Success</ResultCode>
            <Version>14.5.0.53</Version>
         </PingResult>
      </PingResponse>
   </s:Body>
</s:Envelope>
Soap响应如下所示:

With objXMLResponse
    Dim strNode As String
    strNode = "//PingResponse/PingResult/ResultCode"
    If Not .selectSingleNode(strNode) Is Nothing Then
        If .selectSingleNode(strNode).Text = "Success" Then
            MsgBox "We have succeded", vbOKOnly
        Else
            MsgBox "We have failed", vbOKOnly
        End If
    Else
        MsgBox "We have failed", vbOKOnly
    End If
End With
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <PingResponse xmlns="http://avatax.avalara.com/services">
         <PingResult>
            <TransactionId>784293066</TransactionId>
            <ResultCode>Success</ResultCode>
            <Version>14.5.0.53</Version>
         </PingResult>
      </PingResponse>
   </s:Body>
</s:Envelope>

784293066
成功
14.5.0.53

提前感谢您对此提供的帮助。

我有下面的代码,以及您提供的数据示例(我正在点击“We have successed”(我们已成功)消息)可以正常工作

您忘记加载XML文件了吗? 您的代码没有指定如何加载XML数据。如果从文件加载,您有权访问它吗

Option Explicit

Private Sub Command1_Click()

    Dim objXMLResponse As New MSXML2.DOMDocument
    Dim success As Boolean

    success = objXMLResponse.Load("C:\Temp\123.txt")
    If success Then
        With objXMLResponse
            Dim strNode As String
            strNode = "//PingResponse/PingResult/ResultCode"
            If Not .selectSingleNode(strNode) Is Nothing Then
                If .selectSingleNode(strNode).Text = "Success" Then
                    MsgBox "We have succeded", vbOKOnly
                Else
                    MsgBox "We have failed", vbOKOnly
                End If
            Else
                MsgBox "We have failed", vbOKOnly
            End If
        End With
    Else
        MsgBox "Error loading XML file"
    End If
End Sub