本程序将数据库中数据一次性装载到客户端xml数据岛中,然后在客户端处理 用recordset 处理数据。

从数据库中提取数据的程序:xmlDeptMatch.asp


<!-- 
  #include file="../inc/conn.asp" 
  --> 
  
 
  <!-- 
  #include file="../inc/config.asp" 
  --> 
  
 
  <% 
  ... 
  
'生成车间信息的xml文件,其他地方做为数据岛调用
set rs=server.createobject("adodb.recordset")
sql="select id,old_dept,remark,dept_code,dept_name from cst_dept_syn"
rs.open sql,conn,3,1
 
  %> 
  
 
  <? 
  xml version="1.0" encoding="gb2312" 
  ?> 
  
  
  < 
  depts 
  > 
  
 
  <% 
  ... 
   if not rs.eof then
 do while not rs.eof  
  %> 
  
 
  < 
  dept 
  > 
  
 
  < 
  ID 
  > 
  <% 
  ... 
   = rs("id") 
  %> 
  </ 
  ID 
  > 
  
 
  < 
  olddept 
  > 
  <% 
  ... 
   = rs("old_dept") 
  %> 
  </ 
  olddept 
  > 
  
 
  < 
  remark 
  > 
  <% 
  ... 
   = rs("remark")  
  %> 
  </ 
  remark 
  > 
  
 
  < 
  deptcode 
  > 
  <% 
  ... 
   = rs("dept_code")  
  %> 
  </ 
  deptcode 
  > 
  
 
  < 
  deptname 
  > 
  <% 
  ... 
   = rs("dept_name") 
  %> 
  </ 
  deptname 
  > 
  
 
  </ 
  dept 
  > 
  
 
  <% 
  ... 
  rs.movenext
loop
end if 
  %> 
  
 
  </ 
  depts 
  > 
  
  
  <% 
  ... 
  rs.Close
 set rs=nothing
 call closeConn() 
  %> 
 
客户端程序:
 
   
<!--   部门信息数据岛 
  --> 
  
   < 
  xml  
  id 
  ="xmlDept" 
   src 
  ="xmlDeptMatch.asp" 
    async 
  ="false" 
  ></ 
  xml 
  > 
  
   < 
  script  
  language 
  ="vbscript" 
  > 
  ... 
  
  dim rs   '用于装载部门信息的记录集对象
  '装载xml数据
  function xmlLoad(page)
    set rs=document.getElementById("xmlDept").recordset
  end function
  
  '检测xml数据装载状况
  function xmlCheck(page)
    if xmlDept.readystate=4 then
      xmlLoad page
    else
      settimeout "xmlCheck" &page,1
    end if 
 end function
 
 '给部门对象赋属性值并返回部门对象
 sub returnDept(byref p_dept)
    if not (rs.eof and rs.bof) then rs.movefirst
    p_dept.dept_code=""
    p_dept.dept_name=""
    do while not rs.eof
      if trim(rs("remark"))=trim(p_dept.remark) then
        p_dept.dept_name=trim(rs("deptname"))
        p_dept.dept_code=trim(rs("deptcode"))
        exit do
      end if
      rs.movenext
    loop
 end sub
   </ 
  script 
  >

本例子为我工作中曾经做过的。今天发出来了。客户端将数据放到recordset中可以进行比较复杂的操作。此处客户端用的是vbscript.如果改成javascript也很简单。