Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - SAX2 Developer's Guide

Application Form (Simple Filter)

To get started, create a new project and then reference Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office.

To create a new project

To create a reference to MSXML 5.0

  1. On the Project menu, click References.
  2. In the Available References list, select Microsoft XML,v5.0, and then click OK.

Add Controls to the Form

Now you must build the user interface for the simple filter application. Add the following controls to the form.

The form should look like the following.

Add Code to the Form

The code for the form:

Complete Code for the Form

'Create a writer and an attribute helper.
Public oWriter As New MXXMLWriter50
Public atrs As New SAXAttributes50

Private Sub Command1_Click()
'Create the reader.
Dim rdr As New SAXXMLReader50
'Create the content handler.
Dim cnth As New ContentHandlerImpl
'Set the content handler for the reader.
Set rdr.contentHandler = cnth
'Set the error handler for the reader.
Set rdr.errorHandler = cnth
'Set the writer for the content handler.
Set cnth.oContentHandler = oWriter
'Set the error handler for the writer.
Set cnth.oErrorHandler = oWriter

'Configure output for the writer.
oWriter.indent = True
oWriter.standalone = True
oWriter.output = ""
oWriter.omitXMLDeclaration = True

'Set the filter criteria in the content handler.
cnth.SetFilterCriteria (Text3.Text)

On Error GoTo HandleError
    
'Parse the document.
rdr.parseURL (Text2.Text)

Text1.Text = oWriter.output

Exit Sub
    
HandleError:
    If Not cnth.errorHappen Then
        Text1.Text = "**** Error **** " & Err.Number & " : " & Err.Description
    End If
End Sub
Private Sub Command2_Click()
    Unload Me
End Sub

See Also

How Filter Criteria is Set | IMXWriter Interface | MXXMLWriter CoClass | ISAXContentHandler Interface | ISAXErrorHandler Interface