|
 |
资料搜索 |
|
|
|
|
|
|
|
 |
相关文章 |
|
|
|
|
|
|
|
|
|
|
| [ 来源:CSDN | 作者:无从考证 | 时间:2005-9-7 16:00:18 | 浏览:人次 ] | |
|
在处理大型的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
|
|
|
|
|
|
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
|
|
|
|
|
栏目编辑: 设计风 |
责任编辑: 简若宁 |
|
|
原始作者: 无从考证 |
录入时间: 2005-9-7 16:00:18 |
|
|
信息来源: CSDN |
投稿信箱: Edu#chinaz.com |
|
|
|
| |
|