Application Forms (XML Extractor)

MSXML 5.0 SDK

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

Application Forms (XML Extractor)

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

To create a new project

  • Open Microsoft® Visual Basic® 6.0. In the New Project dialog box, double-click Standard EXE.

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.
  3. Save the project.

Build the Main Form

First, you must build the initial form used by the XML Extractor application. Add the following controls to the form.

  • A text box for entering the name of the XML file to be used as input.
  • A label for the text box control.
  • Two command buttons. One is for starting the application. The other is to exit the application.

For your application form to work with the sample code provided in the next section, you must set the properties in the following table.

Control Property Setting
Form Caption "Medical bills (XML Extractor) Example"
Label1 Caption "File name:"
Text1 (Name)

Text

txtFilename

"invoices.xml"

Command1 (Name)

Caption

cmdStart

"Start"

Command2 (Name)

Caption

cmdExit

"Exit"

After you modify the property settings, resize the controls and arrange them on the form until your user interface looks like the following:

Complete Code for the Main Form

The following shows the complete code for the main form. To run the code as you read, select all the text, then copy it and paste it into the form of your own Microsoft® Visual Basic® project.

Option Explicit

Private builder As MXXMLWriter50
Private stylesheet As DOMDocument50

Private Sub cmdExit_Click()
    End
End Sub

Private Sub cmdStart_Click()

    Dim reader  As New SAXXMLReader50
    Dim filter  As New MyExtractor
    Dim builder As New MXXMLWriter50
    
    builder.output = New DOMDocument50
    Set stylesheet = New DOMDocument50
    stylesheet.Load App.Path & "\" & "invoices.xsl"
    
    Set filter.IVBSAXXMLFilter_parent = reader
    Set filter.SAXXMLReader50_contentHandler = builder
    filter.cutElement = "invoice"
    
    On Error GoTo Uh_Oh
    reader.parseURL App.Path & "\" & txtFilename.Text
    
    Exit Sub
    
Uh_Oh:
    MsgBox "*** Error while processing invoices *** " + Err.Description & " (in " & Err.Source & ")"
    
End Sub

Public Sub processInvoice(dom As MSXML2.DOMDocument50, sInvNumber As String)
    Dim s As String
    s = dom.transformNode(stylesheet)
    saveToFile s, App.Path & "\invoice" & sInvNumber & ".html"
    frmInvoice.txtAsXml = dom.xml
    frmInvoice.txtAsHtml = s
    frmInvoice.webPreviewPane.Navigate App.Path & "\invoice" & sInvNumber & ".html"
    frmInvoice.Show vbModal
End Sub

Private Sub saveToFile(text As String, fname As String)
    Open fname For Output As #5
    Print #5, text
    Close #5
End Sub

Build the Secondary Form

Next, add the secondary invoice preview form used by the XML Extractor application.

To add a new form to the project

  1. From the Project menu, click Add Form.
  2. In the Add Form dialog box, click Open.

The preview form should allow the user to step through and preview the invoices as output in a Web browser. To support this feature, use the custom WebBrowser control. This is a custom ActiveX control provided as part of the Microsoft Internet Controls library. Therefore, you must add a reference in your project to this component library.

To create a reference to Microsoft Internet Controls

  1. On the Project menu, click Components.
  2. In the Components dialog box, from the Controls tab, select Microsoft Internet Controls from the list. Click OK.

    The Web Browser control will now appear in the Toolbox, allowing you to add it to the new form.

  3. Save the project.

You can now add the following controls to the form.

  • A custom Web browser control. This enables you to use an embedded Web browser window on your form. This browser control will be used to view each output invoice as a final-formatted HTML file.
  • Two text boxes for showing source text views. One will show the invoices as XML, and one will show the transformed output as HTML.
  • Two command buttons: one to advance to the next invoice in the file, and one to hide the preview window and return to the main form.

For your application form to work with the sample code provided in the next section, you must set the properties in the following table.

Control Property Setting
Form (Name)

Caption

frmInvoice

"Invoice"

Text1 (Name)

MultiLine

ScrollBars

txtAsXml

True

2 - Vertical

Text2 (Name)

MultiLine

ScrollBars

txtAsHtml

True

2 - Vertical

WebBrowser1 (Name) webPreviewPane
Command1 Name

Caption

cmdNext

"Next invoice"

Command2 Name

Caption

cmdBreakAndExit

"Break and exit"

After you modify the property settings, resize the controls and arrange them on the form until your user interface looks like the following:

Complete Code for the Secondary Form

The following shows the complete code for the secondary form. To run the code as you read, select all the text, then copy it and paste it into the form of your own Microsoft® Visual Basic® project.

Private Sub cmdBreakAndExit_Click()
    End
End Sub

Private Sub cmdNext_Click()
    Hide
End Sub

See Also

Extract Data From a Large Document | Overview of the XML Extractor Application | Sample Files (XML Extractor) | MyExtractor Class (XML Extractor) | Run the Application (XML Extractor) | How the XML Extractor Application Works