2014-08-27 74 views
0

我已經使用這個相同的代碼爲許多其他項目,並沒有問題,但由於某種原因,它不會在這裏工作。每當我到達「如果沒有.selectSingleNode(strNode)沒有什麼」然後「它什麼也沒有回來,並把我放到其他地方。我已經能夠驗證下面列出的XML以及正在閱讀的代碼塊。selectSingleNode失敗與肥皂響應VB6

不幸的是,我必須在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 

SOAP響應如下:提前爲任何幫助,這

<?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> 

感謝。

回答

0

我在下面的代碼和它工作正常(我打「我們已經成功」消息)根據您所提供

數據採樣你是不是忘記加載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