ASP怎么读取指定xml 的节点
来源:无忧脚本 时间:2008-04-28 13:12:00
zyw147 提出问题:ASP读取指定xml 的节点?
怎么用ASP《不是JS》取出指定的节点? 例如我想取出北京,我在ASP客户端提交的是 1 ,怎么用1取北京?
<?xml version="1.0" encoding="gb2312"?>
<data>
<book>
<cost>1</cost>
<name>北京</name>
</book>
<book>
<cost>2</cost>
<name>上海</name>
</book>
<book>
<cost>3</cost>
</book>
</data>
XML 不会
解决问题:
方法1.xfdipzone答:
<%
cost=Request("cost")
xmlfile=server.mappath("1.xml")
set objxml=server.createobject("Msxml2.DOMDocument")
objxml.async=false
objxml.load(xmlfile)
set currnodes=objxml.selectsinglenode("/data/book[cost='" & cost & "']")
Response.write currnodes.childnodes(1).text
set currnodes=nothing
set objxml=nothing
%>
方法2.随风缘答:
也可以如此,加了判断获取的cost是否在xml中存在
<%
Dim bookId, bookName, i
bookId = 1
bookName = "没有书"
If Not IsNull(Request("bookId")) Then bookId = Int(Request("bookId"))
Dim strSourceFile, objXML, objRootList
strSourceFile = Server.MapPath("config.xml")
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.load(strSourceFile)
Set objRootList = objXML.documentElement
For i = 0 To objRootList.childNodes.Length -1
If bookId = Int(objRootList.childNodes.Item(i).childNodes.Item(0).text) Then
bookName = objRootList.childNodes.Item(i).childNodes.Item(1).text
Exit For
End If
Next
Set objXML = Nothing
Response.Write(bookName)
%>
标签:节点,xml,asp
0
投稿
猜你喜欢
如何上传一个.SQL文件到远程主机并且执行它来部署一个SQL数据库
2007-09-23 13:03:00
asp中限制重复提交表单的方法
2007-09-20 13:28:00
asp函数判断服务器是否安装了某种组件
2008-10-11 14:45:00
ORACLE常见错误代码的分析与解决(一)
2010-08-02 13:20:00
说说值类型数据“.”操作符的类型转换
2009-12-13 10:39:00
sp_executesql 使用复杂的Unicode 表达式错误的解决方法
2012-01-29 17:58:52
IE6终极备忘单——策略
2010-01-13 13:05:00
IE bug: 消失的绝对定位元素
2009-10-26 17:59:00
解读iPhone平台的一些优秀设计思路
2010-06-24 21:53:00
通过T-SQL语句实现数据库备份与还原的代码
2011-12-01 08:02:15
em和strong的区别
2008-12-23 12:08:00
让ASP组件来保护你的网站,自定义加密方法的使用
2009-11-07 19:27:00
asp函数遍历文件夹代码
2010-06-21 10:38:00
FrontPage2002简明教程七:HTML在FrontPage中的应用
2008-09-17 11:33:00
WEB标准与XHTML 1.0 Transitional等文档类型介绍
2007-10-20 21:18:00
javascript双击自动滚屏单击停止
2008-10-13 13:05:00
ASP编程代码:隐藏图片的真实地址
2008-10-19 17:14:00
用FrontPage制作缩略图和图片重叠效果
2007-11-18 14:45:00
JavaScript,5种调用函数的方法[译]
2009-02-24 16:26:00
Oracle 数据库操作类
2009-08-12 12:06:00