用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
<?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
解决方案 »
- vsflexgrid怎么支持右键
- SQL语句
- 各位帮我看看我的代码问题出在哪儿啊?
- 请问Windows XP中那个文件或者是注册表能够控制网页上传文件打开对话框的路径啊! 我想用vb对其进行修改
- 嵌入OLE的文档的保存问题,送高分!
- 大家去下载Visual Studio Service Pack 6 !
- winsock Error 事件的处理问题,高手老大们来看看啊!
- 如何编写网络语音聊天程序?
- 急问vfp小问题
- vb里面如何用Excel设定的摸版进行数据打印?
- 急活,郁闷了,以前做过都给忘了,请高手帮忙,这是我最后的积分了
- 大侠们,我使用VB在EXCEL中想插入一个新的工作表,怎么出错了,帮我看看吧!谢谢;俄
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....
- <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楼,提供的方法,偶试过了,提取不出来。谢谢!
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