The ContentHandlerImpl
class:
IVBSAXContentHandler
and IVBSAXErrorHandler
interfaces. The methods of these interfaces receive events thrown by the reader. You must add all methods for the implemented interfaces to the ContentHandlerImpl
class.IVBSAXContentHandler
and IVBSAXErrorHandler
interfaces. The oContentHandler
and oErrorHandler
variables are set as properties of the ContentHandler
object in the form and enable the writer to receive ContentHandler
and ErrorHandler
events.FilterCriteria
variable that holds the element name that serves as the criteria for the filter. Also declares a FilterTrue
variable, a Boolean flag used to indicate whether the specified element is within scope. errorHappen
variable, a Boolean flag that indicates whether the ErrorHandler
has thrown a fatal error message. This prevents the ErrorHandler
procedure in the form from overwriting the error message thrown by the error handlerTo create the class
To implement an interface
Implements IVBSAXContentHandler Implements IVBSAXErrorHandler
Note You must implement all methods for the implemented interfaces.
Add the following code to the class.
Note If you already added theImplements
statements, you can simply copy the following code before the firstImplements
statement.
The essential methods used for the filter are discussed in the following topic, Essential Handler Methods.
Option Explicit Implements IVBSAXContentHandler Implements IVBSAXErrorHandler 'Declare a variable for setting the writer to the content handler. Public oContentHandler As IVBSAXContentHandler 'Declare a variable for setting the writer to the error handler. Public oErrorHandler As IVBSAXErrorHandler 'Flag to indicate if the error handler has thrown a fatal error. Public errorHappen As Boolean 'Flag to indicate if the element is in scope. Dim FilterTrue As Boolean 'Declare a string to hold the element name. Dim FilterCriteria As String Private Sub IVBSAXContentHandler_characters(strChars As String) If FilterTrue Then oContentHandler.characters strChars End If End Sub Private Property Set IVBSAXContentHandler_documentLocator(ByVal RHS As _ MSXML2.IVBSAXLocator) Initialize End Property Private Sub IVBSAXContentHandler_endDocument() End Sub Private Sub IVBSAXContentHandler_endElement(strNamespaceURI As String, _ strLocalName As String, _ strQName As String) If FilterTrue Then oContentHandler.endElement strNamespaceURI, strLocalName, _ strQName End If If strLocalName = FilterCriteria Then FilterTrue = False End If End Sub Private Sub IVBSAXContentHandler_endPrefixMapping(strPrefix As String) End Sub Private Sub IVBSAXContentHandler_ignorableWhitespace(strChars As String) End Sub Private Sub IVBSAXContentHandler_processingInstruction(strTarget As _ String, _ strData As String) End Sub Private Sub IVBSAXContentHandler_skippedEntity(strName As String) End Sub Private Sub IVBSAXContentHandler_startDocument() End Sub Private Sub IVBSAXContentHandler_startElement(strNamespaceURI As String, _ strLocalName As String, _ strQName As String, _ ByVal oAttributes As _ MSXML2.IVBSAXAttributes) If strLocalName = FilterCriteria Then FilterTrue = True End If If FilterTrue Then oContentHandler.startElement strNamespaceURI, strLocalName, _ strQName, oAttributes End If End Sub Private Sub IVBSAXContentHandler_startPrefixMapping(strPrefix As String, strURI As String) End Sub Private Sub Initialize() errorHappen = False FilterTrue = False End Sub Private Sub IVBSAXErrorHandler_error(ByVal oLocator As _ MSXML2.IVBSAXLocator, _ strErrorMessage As String, _ ByVal nErrorCode As Long) End Sub Private Sub IVBSAXErrorHandler_fatalError(ByVal oLocator As _ MSXML2.IVBSAXLocator, _ strErrorMessage As String, _ ByVal nErrorCode As Long) Form1.Text1.Text = strErrorMessage & nErrorCode errorHappen = True End Sub Private Sub IVBSAXErrorHandler_ignorableWarning(ByVal oLocator As _ MSXML2.IVBSAXLocator, _ strErrorMessage As _ String, _ ByVal nErrorCode As Long) End Sub Public Sub SetFilterCriteria(elementname) FilterCriteria = elementname End Sub
Essential Handler Methods | IMXWriter Interface | MXXMLWriter CoClass | ISAXContentHandler Interface | ISAXErrorHandler Interface