用vb6怎样读取通过调用WebServices返回的XML中指定的内容,如要读取UID中的内容(VC1035)'**********返回内容*************
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><Get_UserInfoResponse xmlns="http://tempuri.org/"><Get_UserInfoResult><UID>VC1035</UID><PWD>telsafe</PWD><Err /></Get_UserInfoResult></Get_UserInfoResponse></soap:Body></soap:Envelope>
'*****************************Dim strXml As String
Dim str As String
Dim strGet As StringDim new_Node As IXMLDOMNode
Dim oNodes As Object
Dim oNode As Objectstr = "str-aa"'定义soap消息
strXml = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & "?>" & Chr(13) & Chr(10) & _
         "<soap:Envelope xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & " xmlns:xsd=" & Chr(34) & "http://www.w3.org/2001/XMLSchema" & Chr(34) & " xmlns:soap=" & Chr(34) & "http://schemas.xmlsoap.org/soap/envelope/" & Chr(34) & ">" & Chr(13) & Chr(10) & _
         "<soap:Body>" & Chr(13) & Chr(10) & _
         "<Get_UserInfo xmlns=" & Chr(34) & "http://tempuri.org/" & Chr(34) & ">" & Chr(13) & Chr(10) & _
         "<UID>" & str & "</UID>" & Chr(13) & Chr(10) & _
         "</Get_UserInfo>" & Chr(13) & Chr(10) & _
         "</soap:Body>" & Chr(13) & Chr(10) & _
         "</soap:Envelope>"
'-----------------------------
'定义一个http对象,一边向服务器发送post消息
Dim h As MSXML2.ServerXMLHTTP60
'定义一个XML的文档对象,将手写的或者接受的XML内容转换成XML对象
'Dim x As MSXML2.DOMDocument60
Dim x As MSXML2.DOMDocument
'初始化XML对象
'Set x = New MSXML2.DOMDocument60
Set x = New MSXML2.DOMDocument
'将手写的SOAP字符串转换为XML对象
x.loadXML strXml
'初始化http对象
Set h = New MSXML2.ServerXMLHTTP40
'向指定的URL发送Post消息
h.Open "POST", strUrl, flase
h.setRequestHeader "Content-Type", "text/xml"
h.send (strXml)While h.readyState <> 4
Wend'显示返回的XML信息
'Txt_Context.Text = ""
strGet = h.responseText
Txt_Context.SelText = strGet & Chr(13) & Chr(10)'将返回的XML信息解析并且显示返回值
Txt_Context.SelText = Chr(13) & Chr(10)
Set x = New MSXML2.DOMDocument
x.loadXML strGetDim snode As IXMLDOMNode
'Set snode = x.selectSingleNode("Get_UserInfoResult").firstChild
If snode Is Nothing Then
Else
    MsgBox snode.Text
End If

解决方案 »

  1.   

    Dim xmlDoc As New MSXML2.DOMDocument 
    Dim xmlNode As IXMLDOMNodeList xmlDoc.Load "*.xml" 
    Set xmlNode = xmlDoc.documentElement.selectNodes("/根节点/子节点")     comb1.addItem xmlNode.Item(i).nodeName'或oNode.Attributes(i).Text 
    i为0,1,2....
      

  2.   

      <?xml version="1.0" encoding="utf-8" ?> 
    - <UserInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
      <UID>VC1013</UID> 
      <PWD>telsafe</PWD> 
      <Err /> 
      </UserInfo>vb6怎样把UID值(VC1013)和PWD(telsafe)值提取出来,麻烦贴出调试成功的源码,谢谢。急...2楼,提供的方法,偶试过了,提取不出来。谢谢!
      

  3.   

        Dim xmlDoc As MSXML2.DOMDocument
        Dim xmlNode As MSXML2.IXMLDOMNode
        
        Set xmlDoc = New MSXML2.DOMDocument
        If Not xmlDoc.loadXML(strXML) Then
            Debug.Print xmlDoc.parseError.reason, xmlDoc.parseError.srcText
            Exit Sub
        End If
        
        Set xmlNode = xmlDoc.selectSingleNode("//UID")
        Debug.Print xmlNode.Text