日期:2014-05-16  浏览次数:21031 次

ASP如何读取返回的XML
返回的XML内容:
<xml name="sendOnce" result="1">
  <Item cid="80000'>
</xml>

我想读取result的结果。

------解决方案--------------------

s = "<xml name=""sendOnce"" result=""1""><Item cid=""80000""/></xml>"
Set oDoc    = CreateObject("Msxml2.DOMDocument")
With oDoc
.async              = False
.validateOnParse    = False
.preserveWhiteSpace = False
    .resolveExternals   = False
.loadXML s
    If .parseError.errorCode <> 0 Then
        sErrMsg     = .parseError.errorCode & "
------解决方案--------------------
" &_
                      .parseError.srcText & "
------解决方案--------------------
" & .parseError.reason
        Response.Write sErrMsg
    End If
End With
Response.Write oDoc.documentElement.getAttribute("result")
Set oDoc = Nothing

------解决方案--------------------
正好我这几天在做这个。给你贴下代码


'利用asp创建objhttp对象发送请求,一种类似ajax的方式
objHttp.open "POST", "http://XXXXXX.COM", false 
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded" 
objHttp.Send str
'200的意思就不说了。
If objHttp.status=200 Then
Dim PageResponseTime
Set objXML    = CreateObject("MSXML2.DOMDocument")
objXML.async=False
objXML.Load(objHttp.responseXML)
'这里是返回的是错误信息
If objXML.parseError.errorCode <> 0 Then
'错误
Response.Write objXML.parseError.errorCode &vbcrlf
Response.Write objXML.parseError.filepos &vbcrlf
Response.Write "Line: "&objXML.parseError.Line&": "&objXML.parseError.linepos &vbcrlf
Response.Write "Reason: "&objXML.parseError.reason&vbcrlf
Response.Write "Error Data: "&objXML.parseError.srcText 
End If
        '下面开始读取节点的名字了,有个节点是<flightItems></flightItems>
Set objFlight=objXML.getElementsByTagName("flightItems")