当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp中vbscript访问xml文件

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

ASP 中的 asp中vbscript访问xml文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 227 ::
收藏到网摘: n/a

 

要求传入工号 返回员工姓名
'全局数据 考虑这样只要load一次
set Doc = CreateObject("Microsoft.XMLDOM")
Doc.async = false
Doc.load(Server.MapPath("user_cnname.xml"))

function cnname_var (varusername)
dim node,i,nodecount,root
set nodeLis= Doc.getElementsByTagName("user")
nodeCount = nodeLis.length
For i=0 to nodeCount - 1
  if  nodeLis.item(i).childnodes.item(0).text = varusername then
'这里有一点疑惑 为什么是item(2)
    cnname_var = nodeLis.item(i).childnodes.item(2).text
    exit function
  end if
next
cnname_var = varusername
end function

xml文件如下:

<?xml version="1.0" encoding="gb2312"?>

<user_cnname>    
    <user>
      <username>A140</username>
    <cnname>赵建川</cnname>
    </user>
    <user>
      <username>A141</username>
    <cnname>赵建川</cnname>
    </user>
</user_cnname>

但用这种方式还没有直接从数据库时查询来得快,所以也就没有采用这种方式,
用javascript + 数据岛也可以实现查询,但是没有小涉及到事情 在asp代码中不好调用