The DOM to SAX example is Microsoft® Visual Basic® code that executes when you click a command button on the application form. The code in this example performs the following tasks:
DOMDocument
, SAXXMLReader
, and MXXMLWriter
objects.wrt
) object for the value of the ContentHandler
property of the SAX reader (rdr
) object.xmlDoc
) object to the parse
method of the SAX reader.output
property of the SAX writer.To run the code sample
Private Function HandleErrors() MsgBox Err.Description End Function Private Sub Form_Resize() 'Resize text box to size of form. Text1.Width = Form1.Width - 350 Text1.Height = Form1.Height - 750 End Sub Private Sub Form_Load() 'Resize text box to size of form. Text1 = "<?xml version=""1.0""?>" & vbCrLf Text1.Top = 100 Text1.Left = 100 Text1.Width = Form1.Width - 350 Text1.Height = Form1.Height 750 'Create a DOMDocument object. Dim xmlDoc As New DOMDocument50 'Create the SAX reader. Dim rdr As New SAXXMLReader50 'Create the XML writer. Dim wrt As New MXXMLWriter50 On Error GoTo errorHandler 'Load the DOM document. xmlDoc.async = False xmlDoc.Load App.Path & "\books.xml" 'Set properties on the XML writer. wrt.byteOrderMark = True wrt.omitXMLDeclaration = True wrt.indent = True 'Set the XML writer to the SAX content handler. Set rdr.contentHandler = wrt Set rdr.dtdHandler = wrt Set rdr.errorHandler = wrt rdr.putProperty "http://xml.org/sax/properties/lexical-handler", wrt rdr.putProperty "http://xml.org/sax/properties/declaration-handler", wrt 'Parse the DOMDocument object. rdr.parse xmlDoc 'Show the results in the text box. Text1.Text = Text1.Text & wrt.output Exit Sub errorHandler: HandleErrors End Sub
Passing a DOMDocument Object as a Parse() Parameter | ISAXXMLReader Interface | parse Method | DOMDocument | Sample XML File (books.xml)