2014-08-27 97 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