Homepageseo.com
Login
登录[Login]
Reg
注册[Reg]
Member
会员[Member]
BBs
论坛[BBs]
logout
退出[Logout]
Search
搜索[Search]
Search For:        Advanced Search   
Guide: 首页 >> IT技术专栏 >> 建站技术 >> 将SAX加入我们的ASP应用中(1)

将SAX加入我们的ASP应用中(1)

作者: zhepu 来源: 互联网 日期: 2008-07-24,13:06

将SAX加入我们的ASP应用中(1)

[ 作者: hydnoahark  添加时间: 2001-7-25 20:10:21 ]


 

在处理大型的xml文档的时候,在服务器端直接使用xml dom的时候速度是比较慢的,当我第一次接触到sax的时候,我意识
到我们应该在服务器端将dom和sax结合起来以提高我们程序的效率。我们在asp中最常使用的就是使用com来完成这个工作
(也许你有更好的方法)。

废话少说,还是直接进入实际的代码部分了(下面只是包含了最基本的代码而已)。

首先我们创建一个dll来封装sax的功能好了。
测试环境:win2k prof.+msxml3.0 sp1+vb6
要使用sax我们必须引用(reference)microsoft xml 3.0(我的机器安装的是msxml3.0 sp1)

工程名:saxtesting

类名:clssaxtest
方法:public function myxmlparser(xml文件物理路径) as domdocument
代码:
option explicit


public function myxmlparser(byval strxmlfilepath as variant) as domdocument
  dim reader as new saxxmlreader
  dim contenthandler as new contenthandlerimpl
  dim errorhandler as new errorhandlerimpl
 
 
  set reader.contenthandler = contenthandler
  set reader.errorhandler = errorhandler
  on error goto errorhandle
  dim xmlfile as string
  xmlfile = strxmlfilepath
  reader.parseurl (xmlfile)
 
  dim xmldoc as msxml2.domdocument
  set xmldoc = createobject("msxml2.domdocument")
  xmldoc.loadxml strxml
  set myxmlparser = xmldoc
  set xmldoc = nothing
  exit function
 
errorhandle:
  err.raise 9999, "my xml parser", err.number & " : " & err.description

end function

类名:modpublic
代码:
option explicit

global strxml as string

类名:contenthandlerimpl
代码:
option explicit

implements ivbsaxcontenthandler


private sub ivbsaxcontenthandler_startelement(strnamespaceuri as string, strlocalname as string,

strqname as string, byval attributes as msxml2.ivbsaxattributes)
 
  dim i as integer
 
  intlocker = intlocker + 1
  if intlocker > 1 then
     
  end if
  strxml = strxml & "<" & strlocalname
 
  for i = 0 to (attributes.length - 1)
      strxml = strxml & " " & attributes.getlocalname(i) & "=""" & attributes.getvalue(i) &

""""
  next

  strxml = strxml & ">"
 
  if strlocalname = "qu" then
      err.raise vbobjecterror + 1, "contenthandler.startelement", "found element <qu>"
  end if

end sub

private sub ivbsaxcontenthandler_endelement(strnamespaceuri as string, strlocalname as string,

责任编辑: admin 参与评论
免责申明: 本网转载内容均来自互联网,本网并不保证其内容的真实性。如果您认为本网站某部分的内容有侵权嫌疑,敬请立即通知我们,我们将在第一时间予以更改或删除。
Copyright © 2006 HomepageSeo.com ®. All rights reserved. Website development by 八桂网络科技 Author:Homepage 桂ICP备06012988号