The main form provides the user interface for the JumpStart application and consists of four elements.
| Interface Element | Description |
|---|---|
| Text1 | A text box for entering the file name of the file to parse. |
| Command1 | A button to start the parse process. |
| Command2 | A button to exit the application. |
| Text2 | A text box that displays the results of the parse operation. |
In addition to providing the interface elements, the main form also provides code that creates the required instances of the classes and starts the parse process.
| To | The main form uses this code |
|---|---|
Create a new instance of the reader (SAXXMLReader40) |
Dim reader As New SAXXMLReader40 |
Create an instance of ContentHandlerImpl and set it to receive events from the reader |
Dim contentHandler As New ContentHandlerImplSet reader.contentHandler = contentHandler |
Create an instance of ErrorHandlerImpl and set it to receive events from the reader |
Dim errorHandler As New ErrorHandlerImplSet reader.errorHandler = errorHandler |
Create an instance of DTDHandlerImpl and set it to receive events from the reader |
Dim dtdHandler As New DTDHandlerImplSet reader.dtdHandler = dtdHandler |
| Start the parse process | reader.parseURL (txtFilePath.Text) |
The following is the complete code for the main form of the JumpStart application.
Private Sub cmdBrowse_Click()
CommonDialog1.ShowOpen
txtFilePath.Text = CommonDialog1.FileName
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdParse_Click()
Dim reader As New SAXXMLReader40 'Reads the XML document
Dim contentHandler As New ContentHandlerImpl 'Receives parsing events
Dim errorHandler As New ErrorHandlerImpl 'Receive error events
Dim dtdHandler As New DTDHandlerImpl
rtfOutput.Text = ""
Set reader.contentHandler = contentHandler 'They work together
Set reader.errorHandler = errorHandler 'They also work together
Set reader.dtdHandler = dtdHandler
On Error GoTo 10
reader.parseURL (txtFilePath.Text) 'Parse the document
Exit Sub 'That's all, folks!
10: rtfOutput.Text = rtfOutput.Text & "*** Error *** " & Err.Number _
& " : " & Err.Description
End Sub
Private Sub Form_Load()
Dim fso As New FileSystemObject
Dim folder As folder
Dim strSampleFilePath As String
Set folder = fso.GetFolder(".")
strSampleFilePath = fso.GetAbsolutePathName(folder.Path) & "\books.xml"
frmMain.txtFilePath.Text = strSampleFilePath
End Sub
The Exit Sub and line marked 10: are required only if you want to handle processing outside the ErrorHandler. Otherwise, you can use On Error Resume Next.
The following instructions are based on the assumption that you will create a sample data file named "books.xml", however, you can use other XML documents as the input file for this application.
To run the JumpStart application
Note You should save a copy of this sample XML file in the same folder as your copy of the JumpStart project.
If the application starts and runs successfully, the sample file will display as SAX parsed output in the results text box.
This application is intended to provide a simple introduction to SAX2 (Simple API for XML) and serve as a starting point for writing your own SAX-based applications. For more information about the MSXML (Microsoft® XML Parser) implementation of the SAX2 interfaces, see the SAX Reference.
Sample XML File (books.xml) | Overview of the JumpStart Application | Implementing the ContentHandler | Implementing the ErrorHandler | SAX2 Reference
| This HTML Help has been published using the chm2web software. |