Add SAX to our ASP app (1)

zhaozj2021-02-17  47

Add SAX to our ASP app (1)

[Author: hydnoahark Add Time: 2001-7-25 20:10:21]

When processing a large XML document, the speed is slower when the server side is using XML DOM. When I first touched SAX, I realized that we should combine DOM and SAX in the server side. Improve the efficiency of our program. Our most commonly used in ASP is to use COM to complete this job (maybe you have a better way).

Less nonsense, or directly enter the actual code part (below only containing the most basic code).

First we create a DLL to encapsulate SAX's functionality. Test Environment: Win2K Prof. MSXML3.0 SP1 VB6 To use sax we must reference (Reference) Microsoft XML 3.0 (I installed MSXML3.0 SP1)

Engineering Name: SaxTesting

Class name: clssaxtest method: public function myXMLPARSER (XML file physical path) AS DOMDocument code: 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

Caten name: MODPUBLIC code: OPTION Explicit

Global Strxml As String

Class name: ContentHandlerImpl code: 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 & "ing strlocalname =" qu "the Err.raise vbobjectError 1," ContentHandler.StartElement "," Found Element "endiff

End Sub

Private sub ivbsaxcontenthandler_endelement (Strnamespaceuri As String, Strlocalname As String,

转载请注明原文地址:https://www.9cbs.com/read-29903.html

New Post(0)