On the other hand, XML data can be used as a data source of a read-only or read/write recordset in ADO 2.5. For example, you can use ADO 2.5 in an ASP page on a Web server to retrieve data from a database by placing the data into an ADO recordset. The data will then be transferred as XML output to the ASP Response object using ADO 2.5. Once the XML data arrives on the client, it can be read into an ADO recordset on the client using DHTML. Using the client-side ADO recordset and DHTML, the user can read and update the data. Let's look at several examples of inputting and outputting data as XML in ADO 2.5 to see how this works.
Inputting Data as XML Using ADO 2.5
Reading the XML data generated by ADO 2.5 is just as easy as outputting the data. To examine how to input data as XML using ADO 2.5 in the example application, add another command button to the frmADOXML form and call it cmdRetrieve with a caption Retrieve&Add. Add the following code to the click event handler of the command button cmdRetrieve:
Private Sub cmdRetrieve_Click() Dim objNWRecordset As ADODB.Recordset Set objNWRecordset = New ADODB.Recordset 'Open the recordset to a file as XML. objNWRecordset.Open "C:\Products.XML", Options:=adCmdFile 'Add a new record. objNWRecordset.AddNew objNWRecordset.Fields("ProductName") = "Test" End Sub
An error will be raised if you run this code without adding the rs:updatable='true' attribute to the schema section of the generated XML file.
Setting Options to adCmdFile tells ADO that this data will be coming from a regular file and not from a database.
Once you add a new record, edit a record, or delete a record, you must call the Update method of the ADO recordset. Each time you call the Update method, the updated record is marked within the recordset. If you make changes to the recordset and save the changes to a file, you can see the actual changes. These changes are being made only to the recordset, not to the actual data in the database, as there is no connection to the database.