• 网络学院
  • IT资讯
  • 操作系统
  • 网络技术
  • 软件应用
  • 办公软件
  • 编程技术
  • 网站架设
  • 数据库类
  • 平面设计
  • 多媒体类
  • 游戏资讯
  • 教学论文
  • 认证考试
将SAX加入我们的ASP应用中
  站点:
  • 首 页
  • 最新软件
  • 文章教程
  • 国内软件
  • 国外软件
  • 绿色软件
  • 源码下载
  • 字体下载
将SAX加入我们的ASP应用中
软件发布 将SAX加入我们的ASP应用中
网络软件 系统工具 应用软件 联络聊天 图形图像 多媒体类 行业软件 游戏娱乐 编程开发 安全相关 教育教学 数码软件 绿软下载
热门软件: QQ 瑞星 pplive e话通 木马克星 千千静听 office2000 五笔字根 Photoshop 视频分割
返回文章教程首页 >> 文章首页 >> 编程技术 >> XML教程 >> 将SAX加入我们的ASP应用中

将SAX加入我们的ASP应用中

添加时间: 2006-5-10 4:51:30  作者: XML教程  阅读次数:35   来源: http://d9soft.com

        在处理大型的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, 
strQName As String)

strXML = strXML & "</" & strLocalName & ">"

End Sub
Private Sub IVBSAXContentHandler_characters(text As String)
text = Replace(text, vbLf, vbCrLf)
strXML = strXML & text

End Sub
Private Property Set IVBSAXContentHandler_documentLocator(ByVal RHS As MSXML2.IVBSAXLocator)
End Property
Private Sub IVBSAXContentHandler_endDocument()
End Sub
Private Sub IVBSAXContentHandler_endPrefixMapping(strPrefix As String)
End Sub
Private Sub IVBSAXContentHandler_ignorableWhitespace(strChars As String)
End Sub
Private Sub IVBSAXContentHandler_processingInstruction(target As String, data As String)

strXML = strXML & "<?" & target & " " & data & ">"
End Sub
Private Sub IVBSAXContentHandler_skippedEntity(strName As String)
End Sub
Private Sub IVBSAXContentHandler_startDocument()
End Sub
Private Sub IVBSAXContentHandler_startPrefixMapping(strPrefix As String, strURI As String)
End Sub

类名:ErrorHandlerImpl
代码:
Option Explicit
Implements IVBSAXErrorHandler

Private Sub IVBSAXErrorHandler_fatalError(ByVal lctr As IVBSAXLocator, msg As String, ByVal 
errCode As Long)

strXML = strXML & "*** error *** " & msg

End Sub
Private Sub IVBSAXErrorHandler_error(ByVal lctr As IVBSAXLocator, msg As String, ByVal errCode As 
Long)

End Sub
Private Sub IVBSAXErrorHandler_ignorableWarning(ByVal oLocator As MSXML2.IVBSAXLocator, 
strErrorMessage As String, ByVal nErrorCode As Long)
End Sub

OK,让我们编译这个DLL,应该是没什么问题了。让我们在ASP中看看运行的结果怎么样:
XML文件:
<?xml version="1.0"?>
<root foo="bar.com">
<PARTS>
<PART foo="bar.com" foo2="bar.com">
<PARTNO>12345</PARTNO>
<DESCRIPTION>VIP - Very Important Part</DESCRIPTION>
</PART>
<PART>
<PARTNO>5678</PARTNO>
<DESCRIPTION>LIP - Less Important Part</DESCRIPTION>
</PART>
</PARTS>
</root>
ASP文件:
<%
Set a = CreateObject("SAXTesting.clsSAXTest")
Set xmlDoc = a.MyXMLParser("D:\test.xml")
Response.contenttype="text/xml"
response.write xmlDoc.xml
set xmlDoc=nothing
set a=nothing
%>

 

上下文章:

 

上一篇文章: XML Schema学习笔记 下一篇文章: 掌握SAX

相关文章:

  • 我们就是主角!魔兽世界BOSS穆鲁贼攻略
  • 城域网光缆线路设计与技术应用
  • Oracle加入Grails开源计划提升Java生产力
  • 数据库人员手边系列:ORACLE应用源码
  • Oracle平台应用数据库系统的设计与开发[上]

相关软件:

  • 全国专业技术人员计算机应用能力考试模拟 2.1
  • 电脑应用一软通 V1.06
  • 我们的歌(MP3下载软件) V1.30
  • C++语言程序设计及应用实例 PDF电子书
  • 网管应用文萃盛夏版 CHM电子书
  • 计算机应用文摘杂志2006年02期 01月(下) 高清晰PDF

 

快速导航

  • 网络学院
  • 精品汇聚
  • 字体下载
  • 教程下载
  • ASP源码
  • PHP源码
  • Net源码
  • JSP 源码

编程技术分类导航

  • ASP & ASP.NET教程
  • PHP教程
  • JSP教程
  • C/C++教程
  • VB & VB.NET教程
  • VC教程
  • Delphi教程
  • BCB教程
  • VFP教程
  • PB教程
  • JAVA教程
  • XML教程
  • C#教程
  • CGI教程

本类经典文章推荐

  • XML轻松学习手册(6)XML实例解析...
  • XSL简明教程(1)XSL入门
  • XSL简明教程(2)XSL转换
  • XSL简明教程(3)在客户端的实现
  • XSL简明教程(4)在服务器端的实现
  • XSL简明教程(5)XSL的索引
  • XSL简明教程(5)XSL的索引
  • XSL简明教程(6)XSL过滤和查询
  • XSL简明教程(7)XSL 的控制语句
  • XSL简明教程(7)XSL 的控制语句

XML教程阅读排行

  • XML轻松学习手册(6)XML实例解析...
  • XSL简明教程(1)XSL入门
  • 大话XML(1)XML是什么
  • XML轻松学习手册(2)XML快速入门
  • XML轻松学习手册(1)目录
  • XML轻松学习手册(3)XML概念
  • XML轻松学习手册(5)XML语法
  • XSL简明教程(2)XSL转换
  • 大话XML(2)XML和HTML的比较1
  • XML轻松学习手册(6)XML实例解析

编程技术阅读总排行

  • VB入门教程之一
  • Java连接数据库实例
  • 第二章 PowerBuilder 入门之创建新...
  • VC++之List Box/Check List Box控...
  • 第一章 什么是PowerBuilder
  • VC++ List Ctrl控件
  • VC++ Combo Box/Combo Box Ex控件
  • 学C++不得不看的一篇文章
  • VB入门教程之二
  • VC++之Button控件

广告位置

字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 回到顶部

关于我们 | 版权声明 | 免责条款 | 广告联系 | 软件发布 | 下载帮助 | 下载排行 | 网站地图 | 特别鸣谢 | 友情连接

copyright; 2005-2008 D9soft.com 第九软件网 版权所有