Dela via


Loading and Generating XML Using XMLAdapter Class Sample

File: ...\Samples\Solutions\Toledo\XMLAdapter.scx

You can use the XMLAdapter class to create multiple cursors from XML, such as ADO.NET DataSets, and in reverse, generate XML from multiple cursors.

This sample demonstrates some of the many uses for the XMLAdapter class, such as select an XML file to create cursors or generate XML from multiple tables.

For more information, see XMLAdapter Class.

Loading XML

In this sample, you can load an XML DataSet into an XMLAdapter object by clicking Load XML on the XMLTables tab and selecting a valid XML file, such as one generated from an ADO.NET DataSet or another XMLAdapter object. The Click event of the Load XML button contains the following code that uses the XMLAdapterLoadXML method:

ThisForm.oXMLAdapter.LoadXML(cFilename, .T.)

The name of the file you select is passed as the first parameter to the LoadXML method. The second parameter of LoadXML indicates that the first parameter is a file; otherwise, it assumes that the first parameter is a variable that contains the XML string.

After selecting a file, the XMLAdapterTables collection fills with as many XMLTable objects as there are tables in the XML DataSet, which you can use to generate cursors.

Adding Tables

In this sample, you can add tables and generate XML by selecting Add Table on the XMLTables tab, selecting a table, and clicking To XML.

When you select Add Table, a list of Northwind tables appears so you can select one or more tables. After opening a table, the table is added to the XMLAdapter object using the AddTableSchema method as follows:

USE ? SHARED IN 0
cTable = LOWER(ALIAS())
ThisForm.oXMLAdapter.AddTableSchema(cTable)

Generating XML

In this sample, you can generate XML after adding tables to the XMLAdapter object and setting any additional properties on XMLAdapter Properties tab.

To generate XML, select To XML on the XMLTables tab, which calls the XMLAdapterToXML method:

ThisForm.oXMLAdapter.ToXML(XML_FILENAME,, .T., ;
ThisForm.tabXMLAdapter.Page1.chkBefore.Value, ;
ThisForm.tabXMLAdapter.Page1.chkChangesOnly.Value)

In ToXML, leaving the second parameter blank indicates that schema should be generated inline. The third parameter indicates whether the first parameter is the name of a file (True - .T.) or a variable (False - .F.).

See Also

Solutions Samples | XML Functionality Using XMLAdapters