ASP如何读取返回的XML

drifer 2013-04-26 10:26:35
返回的XML内容:
<xml name="sendOnce" result="1">
<Item cid="80000'>
</xml>

我想读取result的结果。
...全文
288 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
drifer 2013-05-07
  • 打赏
  • 举报
回复
已经解决了,函数如下。 '输入url目标网页地址,返回值getHTTPPage是目标网页的html代码 function getHTTPPage(url) dim Http dim xmlDOC set Http=server.Createobject("MSXML2.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if Set xmlDOC=server.CreateObject("Microsoft.XMLDOM") xmlDOC.async = "false" xmlDOC.resolveExternals = "false" xmlDOC.setProperty "ServerHTTPRequest", true xmlDOC.load(http.responseXML) getHTTPPage = xmlDOC.documentElement.getAttribute("result") set xmlDOC = nothing set http=nothing if err.number<>0 then err.Clear end function
Donthan 2013-05-01
  • 打赏
  • 举报
回复
正好我这几天在做这个。给你贴下代码

'利用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")
hookee 2013-04-28
  • 打赏
  • 举报
回复
... Set oNode = oDoc.selectSingleNode("/xml/item") If Not oNode Is Nothing Then Response.Write oNode.getAttribute("cid") End If Set oNode = Nothing
drifer 2013-04-28
  • 打赏
  • 举报
回复
我试下。 我原来是用XML文件测试的,但实际是提交后返回的XML。 请帮我看下以下的函数有什么问题:注(url可以返回一个以上格式的XML) function getHTTPPage(url) dim Http dim xmlDOC set Http=server.Createobject("MSXML2.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if Set xmlDOC=server.CreateObject("MSXML2.DOMDocument") xmlDOC.load(Http.Responsetext) '这里改成: Http.ResponseXML也不行。 getHTTPPage = xmlDOC.documentElement.getAttribute("result") set xmlDOC = nothing set http=nothing if err.number<>0 then err.Clear end function 提示:缺少对象Microsoft VBScript 运行时错误
hookee 2013-04-27
  • 打赏
  • 举报
回复

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
drifer 2013-04-27
  • 打赏
  • 举报
回复
页面提交后的返回XML,我如何加载,然后再读取?请示例,谢谢!
drifer 2013-04-27
  • 打赏
  • 举报
回复
引用 2 楼 hookee 的回复:

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不是.NET,但还是成功了,谢谢! Response.Write oDoc.documentElement.getAttribute("result") 但如果我想读cid的值呢?如果读取??

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧