This class allows you to convert an ADO Recordset to an XML document or load an XML document created with this class, back into an ADO Recordset.
|(Declarations)||Declarations||Declarations and private variables for the CXMLADO class.|
|SourceFile||Property||Get the path and name of the XML source file.|
|Class_Initialize||Initialize||Initialize the class.|
|ADOTOXML||Method||Convert an ADO recordset to an XML document. Note that this does not handle data in binary fields.|
|CreateDocument||Method||Create a default Root Document node.|
|SaveXML||Method||Save an XML document using the SourceFile property.|
|XMLTOADO||Method||Convert an XML document created with the ADOTOXML method to an ADO Recordset.|
|mxmlDocument_OnDataAvailable||Private||Event raised by the XML parser when data is available.|
|mxmlDocument_OnReadyStateChange||Private||Event raised by the XML parser when the Ready State changes.|
' To use this example: ' 1. Create a new form. ' 2. Create the following command buttons: cmdADOToXML, cmdXMLToADO ' 3. Create the following textboxes: txtSourceFile, txtDocName ' 3. Paste the entire contents of this module into the new form's module. ' This example assumes that the sample files are located in the folder named by the following constant Private Const mcstrSamplePath As String = "C:\Total Visual SourceBook 2013\Samples\" Private Const mcstrExampleDB As String = mcstrSamplePath & "sample.mdb" Private Const mcstrQueryString As String = "SELECT * FROM Customers" Private Const mcstrJetProvider351 As String = "Microsoft.Jet.OLEDB.3.51" Private Const mcstrJetProvider4 As String = "Microsoft.Jet.OLEDB.4.0" Private Const mcstrJetProvider12 As String = "Microsoft.ACE.OLEDB.12.0" Private Const mcstrJetProvider14 As String = "Microsoft.ACE.OLEDB.14.0" Private mclsXML As CXMLADO Private mcnn As ADODB.Connection Private mrst As ADODB.Recordset Private Sub cmdADOTOXML_Click() Dim strProvider As String ' Use ACE provider to support the 64-bit version of Access. #If VBA7 Then strProvider = mcstrJetProvider12 #Else strProvider = mcstrJetProvider4 #End If Set mclsXML = New CXMLADO Set mcnn = New ADODB.Connection Set mrst = New ADODB.Recordset mcnn.Open "Provider=" & strProvider & ";Persist Security Info=False;Data Source=" & mcstrExampleDB mrst.Open mcstrQueryString, mcnn, adOpenForwardOnly, adLockReadOnly mclsXML.SourceFile = txtSourceFile.Value mclsXML.CreateDocument txtDocName.Value mclsXML.ADOTOXML mrst mclsXML.SaveXML Set mclsXML = Nothing Set mcnn = Nothing Set mrst = Nothing MsgBox "File Created" End Sub Private Sub cmdXMLTOADO_Click() Dim oFld As ADODB.Field Set mclsXML = New CXMLADO Set mcnn = New ADODB.Connection Set mrst = New ADODB.Recordset mclsXML.SourceFile = txtSourceFile.Value Set mrst = mclsXML.XMLTOADO mrst.MoveFirst Do While Not mrst.EOF For Each oFld In mrst.Fields Debug.Print oFld.name Debug.Print oFld.Value Next oFld mrst.MoveNext Loop Set mclsXML = Nothing Set mcnn = Nothing Set mrst = Nothing MsgBox "File Retrieved" End Sub Private Sub Form_Load() Me.txtSourceFile.Value = mcstrSamplePath & "ADOXMLTEST.XML" Me.txtDocName.Value = "Customers" Me.cmdADOToXML.Caption = "ADO to XML" Me.cmdXMLToADO.Caption = "XML to ADO" End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP