SAX2: A Simple API for XML
by Eldar A. Musayev

Listing One
<?xml version="1.0"?>
<booklist>
<book
  title="Building Microsoft Exchange Applications (Solution Developer Series)"
  author="Peter J. Krebs"
  ISBN="157231334X"
  instock="no">
This book will guide programmers and non-programmers to create a professional
mail-enabled or groupware application in less than a day with Microsoft
Exchange.
</book>
  ...
</booklist>


Listing Two
Private Sub IVBSAXContentHandler_startElement(...parameters skipped ...)
            Form1.TextBox1.text = Form1.TextBox1.text _
                & vbNewLine & attrVal(attributes, "title") _
                & attrVal(attributes, "author", "", " by ", "") _
                & vbNewLine & " -- " _
... other attributes ...
                & attrVal(attributes, "instock", " No inventory data.",_
                                                       ", In stock: ", ".")
End Sub
Private Sub IVBSAXContentHandler_characters(strChars As String)
        Form1.TextBox1.text = Form1.TextBox1.text & text
End Sub


Listing Three
Private parent As MSXML2.IVBSAXXMLReader
Public Property Set IVBSAXXMLFilter_parent _
                             ( ByVal RHS As MSXML2.IVBSAXXMLReader)
    Set parent = RHS
    Set RHS.contentHandler = Me
End Property
Public Property Get IVBSAXXMLFilter_parent() As MSXML2.IVBSAXXMLReader
    IVBSAXXMLFilter_parent = parent
End Property


Listing Four
Public ch As IVBSAXContentHandlerPrivate Property Set _
IVBSAXXMLReader_contentHandler(ByVal RHS As MSXML2.IVBSAXContentHandler)
    Set ch = RHS
End Property
Public Property Get IVBSAXXMLReader_contentHandler() _
                                        As MSXML2.IVBSAXContentHandler
        IVBSAXXMLReader_contentHandler = ch
End Property


Listing Five
Public Sub IVBSAXXMLReader_parseURL(ByVal strURL As String)
    If Not IsEmpty(parent) Then: parent.parseURL strURL
End Sub


Listing Six
Private PutItOut As Boolean
Private Sub IVBSAXContentHandler_startElement(... attributes skipped...)
    Dim i As Integer, s As String
    If strQName = "book" Then
        On Error GoTo noTitle
        s = attributes.getValueFromQName("title")
        If InStr(s, searchKey) > 0 Then
            PutItOut = True
        End If
noTitle:
        On Error GoTo 0

        If PutItOut Then
            If Not IsEmpty(ch) Then
              ch.startElement strNamespaceURI,strLocalName,strQName,attributes
            End If
        End If
    End If
End Sub

Private Sub IVBSAXContentHandler_endElement(strNamespaceURI As String, _
                                 strLocalName As String, strQName As String)
    If PutItOut And Not IsEmpty(ch) Then
        ch.endElement strNamespaceURI, strLocalName, strQName
    End If
    If strQName = "book" Then
        PutItOut = False
    End If
End Sub


Listing Seven
Private Sub IVBSAXContentHandler_characters(text As String)
    If PutItOut And Not IsEmpty(ch) Then
        ch.characters text
    End If
End Sub

2

