抱歉,我知道这是旧时代的东西,但我在这里有点大脑衰退,我只需要一个特定的代码示例来继续......
这是使用远程服务返回的 XML 片段时出现的问题
<pap>
<push-response push-id="99c2d0d3-6cce-4207-88c4-54bc8e852501">
<address address-value="WIN">5557489580</address>
<response-result code="1000"/>
</push-response>
</pap>
几年前我编写了一个简单的 VB 函数,用于从 XML 中提取我想要的数据
<%@ Page Language="VB" explicit="true" validateRequest="false" %>
<%@ Import namespace="ADODB" %>
<%@ Import namespace="WinHttp" %>
<%@ Import namespace="MSXML" %>
<%@ Import namespace="Scripting" %>
Function ExtractDataFromXML2(ByRef sInputXML As String) As String
Dim XMLDom As MSXML.DOMDocument
Dim currNode As MSXML.IXMLDOMNodeList
Dim Node As MSXML.IXMLDOMNode
Dim sError As String
Dim sMessageID As String
Dim sResult As String
XMLDom = New MSXML.DOMDocument
XMLDom.async = False
If (XMLDom.loadXML(sInputXML) = False) Then
sResult = "XML Parse Error: " & XMLDom.parseError.reason & " code=" & XMLDom.parseError.errorCode & " " & Chr(13) & Chr(10)
Else
currNode = XMLDom.selectNodes("//push-response")
For Each Node In currNode
sError = Node.selectSingleNode("response-result").attributes.getNamedItem("code").Text
sMessageID = "rubbish"
If sError = "1000" Then
sResult = Node.selectSingleNode("address").Text & "@" & sMessageID
Else
sResult = "Error " & sError & ": " & Node.selectSingleNode("response-result").attributes.getNamedItem("desc").Text
End If
Next Node
End If
ExtractDataFromXML2 = sResult
End Function
对于我来说,我不记得如何将 GUID push-id 放入我的 sMessageID 当前初始化的“垃圾”
否则工作正常...只需要一行 VB,拜托...?
应该是的。
sMessageID = Node.attributes.getNamedItem("push-id").Text