Microsoft XML Core Services (MSXML) 4.0 - SAX2 Developer's Guide

Implementing the DTDHandler (Visual Basic)

For the JumpStart application, you create the DTDHandler by implementing the IVBSAXDTDHandler interface, as described in the following instructions.

To create the DTDHandlerImpl class

  1. On the Project menu, click Add Class Module.
  2. In the Add Class Module dialog box, double-click Class Module.
  3. On the View menu, select the Properties Window.
  4. In the Properties Window, enter DTDHandlerImpl for the Name property.

To implement the DTDHandlerImpl class

  1. In the Class Window, type Implements, press the spacebar, and then double-click IVBSAXDTDHandler from the drop-down list that appears.
  2. In the Object drop-down list on the left side of the Class Window, select IVBSAXDTDHandler.
  3. In the Procedure drop-down list on the right side of the Class Window, select a method or property to add to the class.
  4. Add the desired code to the selected method or property.
  5. Repeat steps 3 and 4 until you have added the desired methods and properties.
Note   If you have trouble implementing methods and procedures for the DTDHandlerImpl class, refer back to Implementing the ContentHandler to see how methods and properties were implemented for the ContentHandlerImpl class.

Complete Code for the DTDHandlerImpl Class

The following is the complete code for the DTDHandlerImpl class of the JumpStart application.

Option Explicit
Implements IVBSAXDTDHandler

Private Sub IVBSAXDTDHandler_notationDecl(strName As String, _
                  strPublicId As String, strSystemId As String)
  
    Dim msg As String
    msg = "DTD notation declared:" & vbCrLf & _
         "strName: " & strName & vbCrLf & _
         "strPublicId: " & strPublicId & vbCrLf & _
         "strSystemId: " & strSystemId & vbCrLf
    
    frmMain.rtfOutput.Text = frmMain.rtfOutput.Text & "*** DTD handler: notation delcared *** " & _
       vbCrLf & msg
  

End Sub

Private Sub IVBSAXDTDHandler_unparsedEntityDecl(strName As String, strPublicId _
                    As String, strSystemId As String, strNotationName As String)
  
    Dim msg As String
    msg = "Unparsed entity declaration:" & vbCrLf & _
         "strName: " & strName & vbCrLf & _
         "strPublicId: " & strPublicId & vbCrLf & _
         "strNotationName: " & strNotationName & vbCrLf
    
    frmMain.rtfOutput.Text = frmMain.rtfOutput.Text & "*** DTD handler: unparsed entity delcared *** " & _
       vbCrLf & msg

End Sub

In order to see DTD events being processed, use an XML file that includes notation declarations and unparsed entity declarations as input. The following is an example of such a file.

<?xml version="1.0"?>
<!DOCTYPE catalog [
<!ELEMENT catalog    (book+) >
<!ELEMENT book       (author, title, genre, price, description, cover) >
<!ATTLIST book id ID #REQUIRED>
<!ELEMENT author         (#PCDATA)   >
<!ELEMENT title          (#PCDATA)   >
<!ELEMENT genre          (#PCDATA)   >
<!ELEMENT price          (#PCDATA)   >
<!ELEMENT description    (#PCDATA)   >
<!ELEMENT cover         EMPTY >
<!ATTLIST cover src ENTITY #REQUIRED>
<!NOTATION jpg SYSTEM "jpeg picture format" >
<!ENTITY xdg134 SYSTEM "graphics/xdg134.jpg" NDATA jpg >
]>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <description>An in-depth look at creating applications with
      XML.</description>
      <cover src="xdg134" />
   </book>
</catalog>

See Also

Overview of the JumpStart Application | Implementing the ContentHandler | Implementing the DTDHandler | Creating the Main Form

This HTML Help has been published using the chm2web software.